Andreas Lundgren Andreas Lundgren - 1 year ago 73
Java Question

Can I tell gradle that two different dependency modules are actually the same and make it pick the one with highest version?

I have a project depending on Netflix Feign and Glassfish Jersey implementation.

Feign uses the 1.1 spec of JAX-RS (JSR 311), and glassfish jersey implementation uses the 2.0 spec. The 2.0 is backward compatible, but the Gradle dependency name is changed.

Thus I have two dependencies in my project:



Both implements the same classes in the same packages, but one according to 1.x and one according to 2.x

In my Java code, I can only point out the class name and the package.

Can I tell Gradle that this actually is the same package although the name differs and in that way only get one set of the implementing classes in the class path?

Right now it is random what version of the classes that the JVM and Compiler picks. Sometime it does not compile, sometimes it compiles but does not run (MethodNotFoundException).

Answer Source

In the end, I added this to my gradle file and it looks alright:

configurations.all {
    resolutionStrategy.dependencySubstitution {
        substitute module('') with module('')

The dependency tree no longer includes the dependency, and no more MethodNotFound-exception for method.