Reputation: 955
I have a project with two dependencies (third-party libraries), and unfortunately their names and versions are same:
pom.xml:
<dependencies>
<dependency>
<groupId>a</groupId>
<artifactId>artifact</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>b</groupId>
<artifactId>artifact</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
Both dependencies have same artifactId
and version
, but different groupId
.
I need to create a distribution package for my project. All dependencies must be copied to lib/
folder. Here is a minimal configuration for maven-assembly-plugin
, assembly.xml:
<id>package</id>
<formats>
<format>dir</format>
</formats>
<baseDirectory>/</baseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
As a result both dependencies should be copied to lib/
inside of zip archive, but actually only one artifact is there:
$ find target/project-1.0-SNAPSHOT-package/
target/project-1.0-SNAPSHOT-package/
target/project-1.0-SNAPSHOT-package/lib
target/project-1.0-SNAPSHOT-package/lib/artifact-1.0-SNAPSHOT.jar
As one of possible solutions, jar file name should include groupId
- then name conflict should disappear.
So the question is: how can I configure maven-assembly-plugin
(or some other plugin) to include both dependencies into my distribution archive?
Upvotes: 4
Views: 961
Reputation: 72844
Try setting outputFileNameMapping
in the dependency set to include the group ID:
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<outputFileNameMapping>${artifact.groupId}-${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
</dependencySet>
Upvotes: 4