-
Notifications
You must be signed in to change notification settings - Fork 181
[MDEP-976] Fix artifact overwrites in copy-dependencies #523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,25 +153,27 @@ protected void doExecute() throws MojoExecutionException { | |
DependencyStatusSets dss = getDependencySets(this.failOnMissingClassifierArtifact, addParentPoms); | ||
Set<Artifact> artifacts = dss.getResolvedDependencies(); | ||
|
||
boolean effectivePrependGroupId = prependGroupId || prependGroupIdByDefault; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need both? One feels like it should be enough There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thank you for your feedback! The @elharo
|
||
|
||
if (!useRepositoryLayout) { | ||
Map<String, Integer> 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); | ||
} | ||
for (Map.Entry<String, Integer> entry : copies.entrySet()) { | ||
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() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be unclear to readers what the original behavior was.