From ff9d86571ed67058740a17204cc6aa975f1dabdb Mon Sep 17 00:00:00 2001 From: Ndacyayisenga-droid Date: Wed, 23 Apr 2025 06:26:31 +0300 Subject: [PATCH 1/2] MDEP-976: Fix artifact overwrites in copy-dependencies --- .../fromDependencies/CopyDependenciesMojo.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java index 0d6eb7d73..80ed8dd1d 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java @@ -105,6 +105,15 @@ public class CopyDependenciesMojo extends AbstractFromDependenciesMojo { @Parameter(property = "mdep.copySignatures", defaultValue = "false") protected boolean copySignatures; + /** + * Prepend the groupId to the output filename by default to avoid conflicts when artifactIds are not globally unique. + * Set to false to retain the original behavior. + * + * @since 3.8.2 + */ + @Parameter(property = "mdep.prependGroupIdByDefault", defaultValue = "true") + protected boolean prependGroupIdByDefault; + @Inject // CHECKSTYLE_OFF: ParameterNumber public CopyDependenciesMojo( @@ -144,11 +153,13 @@ protected void doExecute() throws MojoExecutionException { DependencyStatusSets dss = getDependencySets(this.failOnMissingClassifierArtifact, addParentPoms); Set artifacts = dss.getResolvedDependencies(); + boolean effectivePrependGroupId = prependGroupId || prependGroupIdByDefault; + if (!useRepositoryLayout) { Map copies = new HashMap<>(); for (Artifact artifactItem : artifacts) { String destFileName = DependencyUtil.getFormattedFileName( - artifactItem, stripVersion, prependGroupId, useBaseVersion, stripClassifier); + artifactItem, stripVersion, effectivePrependGroupId, useBaseVersion, stripClassifier); int numCopies = copies.getOrDefault(destFileName, 0); copies.put(destFileName, numCopies + 1); } @@ -162,7 +173,7 @@ protected void doExecute() throws MojoExecutionException { for (Artifact artifact : artifacts) { copyArtifact( - artifact, isStripVersion(), this.prependGroupId, this.useBaseVersion, this.stripClassifier); + artifact, isStripVersion(), effectivePrependGroupId, this.useBaseVersion, this.stripClassifier); } } else { ProjectBuildingRequest buildingRequest = getRepositoryManager() From 031ed9c6a927030c992d7d0f260f4236db79eec6 Mon Sep 17 00:00:00 2001 From: Ndacyayisenga-droid Date: Tue, 6 May 2025 04:11:50 +0300 Subject: [PATCH 2/2] set default to false annd log a warning Signed-off-by: Ndacyayisenga-droid --- .../dependency/fromDependencies/CopyDependenciesMojo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java index 80ed8dd1d..3c49a5cd1 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java @@ -111,7 +111,7 @@ public class CopyDependenciesMojo extends AbstractFromDependenciesMojo { * * @since 3.8.2 */ - @Parameter(property = "mdep.prependGroupIdByDefault", defaultValue = "true") + @Parameter(property = "mdep.prependGroupIdByDefault", defaultValue = "false") protected boolean prependGroupIdByDefault; @Inject @@ -167,7 +167,7 @@ protected void doExecute() throws MojoExecutionException { if (entry.getValue() > 1) { getLog().warn("Multiple files with the name " + entry.getKey() + " in the dependency tree."); getLog().warn( - "Not all JARs will be available. Consider using prependGroupId, useSubDirectoryPerArtifact, or useRepositoryLayout."); + "Not all JARs will be available. To avoid this, consider setting -Dmdep.prependGroupId=true or enabling useSubDirectoryPerArtifact or useRepositoryLayout."); } }