This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit a3e049f9cf0c4fae67af4acb9af91493b3fceb71
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sat Nov 14 13:08:48 2026 +0100

    [MDEP-488] Add useRepositoryLayout to build-classpath
    
    Together with prefix, every artifact, including modules of the same reactor 
whose files are in target/, gets a repository-layout path under the prefix. 
Corrects the prefix javadoc, which claimed the paths are in the local 
repository when no prefix is set.
---
 .../invoker.properties                             | 18 +++++
 .../module-a/pom.xml                               | 32 ++++++++
 .../module-b/pom.xml                               | 94 ++++++++++++++++++++++
 .../build-classpath-repository-layout/pom.xml      | 44 ++++++++++
 .../verify.groovy                                  | 42 ++++++++++
 .../fromDependencies/BuildClasspathMojo.java       | 27 ++++++-
 src/site/markdown/usage.md.vm                      | 12 +++
 7 files changed, 267 insertions(+), 2 deletions(-)

diff --git 
a/src/it/projects/build-classpath-repository-layout/invoker.properties 
b/src/it/projects/build-classpath-repository-layout/invoker.properties
new file mode 100644
index 00000000..2e199f7b
--- /dev/null
+++ b/src/it/projects/build-classpath-repository-layout/invoker.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals = clean package
diff --git a/src/it/projects/build-classpath-repository-layout/module-a/pom.xml 
b/src/it/projects/build-classpath-repository-layout/module-a/pom.xml
new file mode 100644
index 00000000..9e07235e
--- /dev/null
+++ b/src/it/projects/build-classpath-repository-layout/module-a/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.maven.its.dependency</groupId>
+    <artifactId>build-classpath-repository-layout</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>module-a</artifactId>
+</project>
diff --git a/src/it/projects/build-classpath-repository-layout/module-b/pom.xml 
b/src/it/projects/build-classpath-repository-layout/module-b/pom.xml
new file mode 100644
index 00000000..f2c8612b
--- /dev/null
+++ b/src/it/projects/build-classpath-repository-layout/module-b/pom.xml
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.maven.its.dependency</groupId>
+    <artifactId>build-classpath-repository-layout</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>module-b</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.its.dependency</groupId>
+      <artifactId>module-a</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <!-- negative control: without prefix the reactor module is the file 
in its build output -->
+          <execution>
+            <id>no-prefix</id>
+            <phase>package</phase>
+            <goals>
+              <goal>build-classpath</goal>
+            </goals>
+            <configuration>
+              <outputFile>${project.build.directory}/no-prefix.txt</outputFile>
+              <useRepositoryLayout>true</useRepositoryLayout>
+            </configuration>
+          </execution>
+          <!-- negative control: the prefix alone gives file names without 
directories -->
+          <execution>
+            <id>prefix-only</id>
+            <phase>package</phase>
+            <goals>
+              <goal>build-classpath</goal>
+            </goals>
+            <configuration>
+              
<outputFile>${project.build.directory}/prefix-only.txt</outputFile>
+              <prefix>repository</prefix>
+            </configuration>
+          </execution>
+          <execution>
+            <id>layout</id>
+            <phase>package</phase>
+            <goals>
+              <goal>build-classpath</goal>
+            </goals>
+            <configuration>
+              <outputFile>${project.build.directory}/layout.txt</outputFile>
+              <prefix>repository</prefix>
+              <useRepositoryLayout>true</useRepositoryLayout>
+              <pathSeparator>:</pathSeparator>
+              <fileSeparator>/</fileSeparator>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/projects/build-classpath-repository-layout/pom.xml 
b/src/it/projects/build-classpath-repository-layout/pom.xml
new file mode 100644
index 00000000..80f2155d
--- /dev/null
+++ b/src/it/projects/build-classpath-repository-layout/pom.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.dependency</groupId>
+  <artifactId>build-classpath-repository-layout</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <name>Test</name>
+  <description>
+    Test dependency:build-classpath with prefix and useRepositoryLayout in a 
reactor
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <modules>
+    <module>module-a</module>
+    <module>module-b</module>
+  </modules>
+</project>
diff --git a/src/it/projects/build-classpath-repository-layout/verify.groovy 
b/src/it/projects/build-classpath-repository-layout/verify.groovy
new file mode 100644
index 00000000..a5e241fb
--- /dev/null
+++ b/src/it/projects/build-classpath-repository-layout/verify.groovy
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.*;
+import java.util.*;
+
+def read = { String name -> new File( basedir, "module-b/target/" + name 
).text.trim() }
+
+// no prefix: the reactor module is its build output, the other artifact is in 
the local repository
+def noPrefix = read( "no-prefix.txt" ).split( File.pathSeparator ) as List
+assert noPrefix.size() == 2
+assert noPrefix.any { it.replace( '\\', '/' ).endsWith( 
"/module-a/target/module-a-1.0-SNAPSHOT.jar" ) } : noPrefix
+assert noPrefix.any { it.replace( '\\', '/' ).endsWith( 
"/junit/junit/3.8.1/junit-3.8.1.jar" ) } : noPrefix
+assert noPrefix.every { !it.startsWith( "repository" ) } : noPrefix
+
+// prefix without layout: file names only
+assert read( "prefix-only.txt" ).split( File.pathSeparator ) as Set ==
+    [ "repository" + File.separator + "module-a-1.0-SNAPSHOT.jar",
+      "repository" + File.separator + "junit-3.8.1.jar" ] as Set
+
+// prefix with layout: the same for the reactor module and the external 
artifact
+assert read( "layout.txt" ).split( ":" ) as Set ==
+    [ 
"repository/org/apache/maven/its/dependency/module-a/1.0-SNAPSHOT/module-a-1.0-SNAPSHOT.jar",
+      "repository/junit/junit/3.8.1/junit-3.8.1.jar" ] as Set
+
+return true
diff --git 
a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
 
b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
index 720bf82a..d948d402 100644
--- 
a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
+++ 
b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
@@ -83,12 +83,27 @@ public class BuildClasspathMojo extends 
AbstractDependencyFilterMojo implements
     private boolean stripClassifier = false;
 
     /**
-     * The prefix to prepend on each dependent artifact. If undefined, the 
paths refer to the actual files store in the
-     * local repository (the stripVersion parameter does nothing then).
+     * The prefix to prepend on each dependent artifact. If undefined, the 
paths refer to the actual files of the
+     * resolved artifacts: files in the local repository, or the build output 
(<code>target/classes</code> or the
+     * packaged file) for artifacts of modules in the same reactor. In that 
case the stripVersion, prependGroupId and
+     * useRepositoryLayout parameters do nothing.
+     * If defined, each path is the prefix followed by the artifact file name 
only (or by the
+     * repository layout path if {@link #useRepositoryLayout} is {@code 
true}), independent of where the artifact
+     * file actually is.
      */
     @Parameter(property = "mdep.prefix")
     private String prefix;
 
+    /**
+     * Only used together with {@link #prefix}. If {@code true}, each path is 
built in the layout of a Maven
+     * repository below the prefix, for example 
<code>prefix/junit/junit/3.8.1/junit-3.8.1.jar</code>, for every
+     * artifact including those of modules in the same reactor, whose files 
are in the build output directory.
+     *
+     * @since 3.12.0
+     */
+    @Parameter(property = "mdep.useRepositoryLayout", defaultValue = "false")
+    private boolean useRepositoryLayout;
+
     /**
      * If defined, the name of a property to which the classpath string will 
be written.
      * If neither this nor the outputFile parameter is set, the classpath will 
be logged at INFO level.
@@ -288,6 +303,14 @@ public class BuildClasspathMojo extends 
AbstractDependencyFilterMojo implements
         } else {
             sb.append(prefix);
             sb.append(File.separator);
+            if (useRepositoryLayout) {
+                sb.append(artifact.getGroupId().replace('.', 
File.separatorChar))
+                        .append(File.separatorChar)
+                        .append(artifact.getArtifactId())
+                        .append(File.separatorChar)
+                        .append(artifact.getBaseVersion())
+                        .append(File.separatorChar);
+            }
             sb.append(DependencyUtil.getFormattedFileName(
                     artifact, this.stripVersion, this.prependGroupId, 
this.useBaseVersion, this.stripClassifier));
         }
diff --git a/src/site/markdown/usage.md.vm b/src/site/markdown/usage.md.vm
index 407e499b..19d7a644 100644
--- a/src/site/markdown/usage.md.vm
+++ b/src/site/markdown/usage.md.vm
@@ -704,6 +704,18 @@ or to write the classpath to cp.txt:
 mvn dependency:build-classpath -Dmdep.outputFile=cp.txt
 ```
 
+Without `prefix`, each entry is the actual file of the artifact. In a 
multi-module build, the file of a module in the same reactor is in its build 
output (`target/classes`, or the packaged file after `package`), not in the 
local repository. To get a classpath that is the same for every artifact, set 
`prefix` together with `useRepositoryLayout`. Each entry then has the layout of 
a Maven repository below the prefix:
+
+```
+mvn package dependency:build-classpath -Dmdep.prefix=repository 
-Dmdep.useRepositoryLayout=true -Dmdep.outputFile=cp.txt
+```
+
+```
+repository/org/example/module-a/1.0-SNAPSHOT/module-a-1.0-SNAPSHOT.jar:repository/junit/junit/3.8.1/junit-3.8.1.jar
+```
+
+`useRepositoryLayout` has no effect without `prefix`. With `prefix` alone, 
each entry is the prefix followed by the file name only.
+
 The goal can also be bound to a lifecycle phase with the following 
configuration:
 
 ```xml

Reply via email to