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..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 @@ -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 = "false") + 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); } @@ -156,13 +167,13 @@ 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."); } } for (Artifact artifact : artifacts) { copyArtifact( - artifact, isStripVersion(), this.prependGroupId, this.useBaseVersion, this.stripClassifier); + artifact, isStripVersion(), effectivePrependGroupId, this.useBaseVersion, this.stripClassifier); } } else { ProjectBuildingRequest buildingRequest = getRepositoryManager()