简体   繁体   中英

maven-assembly-plugin and jar name conflict

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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM