简体   繁体   中英

how to use apache-maven-shade plugin to resovle multi dependency conflict

Maven shade plugin is very powerful for resolving dependency conclict, but a situation I have is as follows:

myproject

  • guava 31
  • thridparty-dependency-1
    • guava18

I could relocate the guava 31 dependency and then the conflict will be resolved. And how about following situation:

myproject

  • thirdparty-1
    • guava31
  • thirdparty-2
    • guava18
  • thirdparty-3
    • guava4

Or how about if there are more than two dependencies conflicting as the same dependency but with different versions?

If I use relocation, then thirdparty-1/guava31 will be relocated but the guava18 and guava4 still conflict.

I'm not sure how to handle this situation.

You need to de-conflict these across the whole project, not just for the shaded uber-jar.

Use Maven <exclusions> in the pom.xml declarationtion to achieve this.

For example:

    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j</artifactId>
        <version>${neo4j.version}</version>
        <exclusions>
            <exclusion>
                <groupId>io.netty</groupId>
                <artifactId>netty-transport-native-epoll</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-transport-native-epoll</artifactId>
        <version>${netty.version}</version>
    </dependency>

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