Skip to content

[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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

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.

*
* @since 3.8.2
*/
@Parameter(property = "mdep.prependGroupIdByDefault", defaultValue = "false")
protected boolean prependGroupIdByDefault;

@Inject
// CHECKSTYLE_OFF: ParameterNumber
public CopyDependenciesMojo(
Expand Down Expand Up @@ -144,25 +153,27 @@ protected void doExecute() throws MojoExecutionException {
DependencyStatusSets dss = getDependencySets(this.failOnMissingClassifierArtifact, addParentPoms);
Set<Artifact> artifacts = dss.getResolvedDependencies();

boolean effectivePrependGroupId = prependGroupId || prependGroupIdByDefault;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need both? One feels like it should be enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need both? One feels like it should be enough

Thank you for your feedback! The prependGroupId and prependGroupIdByDefault parameters serve distinct purposes to balance backward compatibility and new functionality.

@elharo prependGroupIdByDefault allows enabling groupId prepending by default to avoid filename conflicts, with a default value of false to preserve existing behavior.

prependGroupId provides users with the ability to explicitly override this default on a per-execution basis.


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()
Expand Down