fhuertas
fhuertas

Reputation: 5483

Resolving dependencies of incompatible versions of a library in Maven

I have problems with dependencies in Maven-Java. My problem is that two modules have a dependency with different versions and these versions are incompatible. Can I solve it?

A example of the problem

I have three modules (MA, MB and MC) and two libraries (LA and LB), LA has two versions (v1 and v2) and they are incompatible

The first module, MA, contains the main class and It depends on MB and MC

MB module depends on LA v2.

MC module depends on LB version.

LB version depends on LA v1.

Finally, the tree of dependencies is the following:

MA
| - MB
|   | - LA (v2) 
| - MC
|   | - LB  
|   |    | LA (v1) 

Upvotes: 2

Views: 2101

Answers (2)

fhuertas
fhuertas

Reputation: 5483

This is a Java problem and there is not solution without other technologies like OSGi

Upvotes: -1

Iker Aguayo
Iker Aguayo

Reputation: 4115

I do not know if you consider. In Maven exists one thing called Exclusions.

Extracted from the documentation:

Since maven 2.x resolves dependencies transitively, it is possible for unwanted dependencies to be included in your project's classpath. Projects that you depend on may not have declared their set of dependencies correctly, for example. In order to address this special situtation, maven 2.x has incorporated the notion of explicit dependency exclusion. Exclusions are set on a specific dependency in your POM, and are targeted at a specific groupId and artifactId. When you build your project, that artifact will not be added to your project's classpath by way of the dependency in which the exclusion was declared.

Here the link, maybe it could help you to implement the configuration in your pom.xml --> Maven Exclusions

Upvotes: 3

Related Questions