Resolving dependencies of incompatible versions of a library in Maven

南笙酒味 提交于 2019-12-08 03:59:42

问题


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) 

回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/28625140/resolving-dependencies-of-incompatible-versions-of-a-library-in-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!