How can Maven Shade Plugin relocate multiple versions of a transitive dependency?

1.2k views Asked by At

I have two dependencies, artifact-a and artifact-b. Each depends on a different version of artifact-c. How can I shade artifacts to use these different dependencies? (Or else to have artifact-a use a shaded dependency and artifact-b use the normal one.

        <dependency>
            <groupId>group-a</groupId>
            <artifactId>artifact-a</artifactId>
            <version>2.1.0</version>
<!-- artifact-a uses version 3 of artifact-c.
How do I relocate version 3 without conflicting with version 4?
                <groupId>group-c</groupId>
                <artifactId>artifact-c</artifactId>
                <version>3.0.0</version>
-->
      </dependency>
        <dependency>
            <groupId>group-b</groupId>
            <artifactId>artifact-b</artifactId>
            <version>1.5.0</version>
<!-- artifact-b uses version 4 of artifact-c. 
How do I relocate version 4 without conflicting with version 3?
                <groupId>group-c</groupId>
                <artifactId>artifact-c</artifactId>
                <version>4.0.0</version>
-->
      </dependency>
1

There are 1 answers

0
Joshua Fox On

This can probably done by creating new Maven modules whose only purpose is to shade artifact-a and its dependencies (respectively artifact-b). Then, the main module would depend on these two new modules.