Victor Stafusa
Victor Stafusa

Reputation: 14623

How to exclude cyclic deprecated dependencies in maven without killing the dependencies completely?

I have a case that I have the following cyclic dependencies in maven:

JAR A version 1.1 depends on JAR B version 1.0
JAR B version 1.1 depends on JAR A version 1.0

For some reason that I don't know, Maven brings all the 4 JARs: A 1.0, A 1.1, B 1.0 and B 1.1, which results in a classpath conflict.

This really sucks. I already ask the developers of both JARs to fix this, however I can't simply sit and wait for the day that they decide to fix this.

I tried this:

<dependency>
    <groupId>groupA</groupId>
    <artifactId>artifactA</artifactId>
    <version>1.1</version>
    <type>pom</type>
    <scope>compile</scope>
    <exclusions>
        <exclusion>
            <groupId>groupB</groupId>
            <artifactId>artifactB</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>groupB</groupId>
    <artifactId>artifactB</artifactId>
    <version>1.1</version>
    <type>pom</type>
    <scope>compile</scope>
    <exclusions>
        <exclusion>
            <groupId>groupA</groupId>
            <artifactId>artifactA</artifactId>
        </exclusion>
    </exclusions>
</dependency>

The result is that maven excludes all of the JARs as if none dependency were added, and the project does not compiles because there are missing classes.

So, other than just asking both JARs developers to solve this, what can I do? How can I import both the new dependencies while leaving out both the old ones?

Upvotes: 1

Views: 2582

Answers (1)

Zoran Regvart
Zoran Regvart

Reputation: 4690

Pragmatic solution would be to redeclare the unwanted dependencies as provided, for example:

<dependency>
  <groupId>groupA</groupId>
  <artifactId>artifactA</artifactId>
  <version>1.0</version>
  <scope>provided</scope>
</dependency>

I'm not particularly fond of using provided in such manner, since it leaves the dependency in the compile time and could lead to unwanted compile dependencies, but I see no other way in your case ;(.

Upvotes: 1

Related Questions