Conflict between maven-assembly-plugin and jar name
I have a project with two dependencies (third party libraries) and unfortunately their names and versions are the 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 are the same artifactId
and version
but different groupId
.
I need to create a distribution for my project. All dependencies should be copied to a folder lib/
. Below is the minimum 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 have to be copied to lib/
inside the zip archive, but in reality there is only one artifact:
$ 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 possible solution, the name of the jar file should include groupId
- then the name conflict should disappear.
So the question is, how do I configure maven-assembly-plugin
(or some other plugin) to include both dependencies in my distribution archive?
source to share
Try installing outputFileNameMapping
on a set of dependencies to include the group id:
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<outputFileNameMapping>${artifact.groupId}-${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
</dependencySet>
source to share