0

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>
Joshua Fox
  • 18,704
  • 23
  • 87
  • 147
  • could you try using ` group-c:artifact-c:*:4.0.0 group-c:artifact-c:*:3.0.0 ` within maven shade configuration. – Naman Jan 08 '17 at 19:12
  • I don't think this is possible. Normally Maven will ignore one of the dependencies (it will say "omitted for version x.y.z" when you analyze the dependencies). Using two different dependencies containing the same classes won't work unless you've seperated the dependencies completely using different class loaders. – john16384 Jan 08 '17 at 19:23
  • @nullpointer thank you, but I can't exclude either of these versions of "c", since "a" and "b" require different versions of "c". – Joshua Fox Jan 09 '17 at 07:17

1 Answers1

1

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.

Joshua Fox
  • 18,704
  • 23
  • 87
  • 147