0

I am stuck on a dependency conflict in a multiple project system, where multiple versions of the same dependency coexist.

I created a simple demo project at GitHub.

A has two dependencies: B and C.

B has a dependency: C.

A and B both depend on C but with different version.

A dependends on C.2

B dependends on C.1

Here is the simple dependency graph:

A
|
|___ C.2
|
|___ B
     |
     |__ C.1

A

build.gradle

dependencies {

compile 'org.mindfulrunner:c:2.0'
compile 'org.mindfulrunner:b:1.0-SNAPSHOT'

B

build.gradle

dependencies {

compile 'org.mindfulrunner:c:1.0'

Running testNaming() in B works where c.1 is required and c.1 is only available version of C. But running testNaming_from_b() in A is failing because c.1 is required but c.2 takes over.

Following is the error output. c.1 is an abstract class while c.2 is an interface.

class org.mindfulrunner.NamingV1 has interface org.mindfulrunner.Naming as super class java.lang.IncompatibleClassChangeError: class org.mindfulrunner.NamingV1 has interface org.mindfulrunner.Naming as super class

According to Gradle doc, when resolving dependency conflict, Gradle will select highest version. So when c.1 and c.2 both are present, c.2 will be chosen.

How can I make B use c.1 but not c.2 from within A? I played around changing build.gradle with the ideas from Customizing resolution of a dependency directly. But none of them works.

Any help is highly appreciated!

  • 1
    Does this answer your question? [Java, Classpath, Classloading => Multiple Versions of the same jar/project](https://stackoverflow.com/questions/6105124/java-classpath-classloading-multiple-versions-of-the-same-jar-project) – jannis May 18 '21 at 07:58
  • Thanks Jannis! But I am looking for a configuration inside Gradle script where all different library dependencies with versions are managed together. We are not writing code to manage the JARs directly. But thanks for your answer which reminds me things eventually will still be boiled down to classloading / classpath without magic. – user2142271 May 19 '21 at 00:07

0 Answers0