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

287 Views Asked by At

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.

1

There are 1 best solutions below

0
Stewart On

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>