解决 Maven 中库的不兼容版本的依赖关系

Resolving dependencies of incompatible versions of a library in Maven

我在 Maven-Java 中遇到依赖项问题。我的问题是两个模块具有不同版本的依赖关系,并且这些版本不兼容。我能解决吗?

问题示例

我有三个模块(MA、MB 和 MC)和两个库(LA 和 LB),LA 有两个版本(v1 和 v2)并且它们不兼容

第一个模块,MA,包含主要的class并且依赖于MB和MC

MB 模块依赖于 LA v2。

MC 模块取决于 LB 版本。

LB 版本取决于 LA v1。

最后,依赖关系树如下:

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

不知你是否考虑过。在 Maven 中存在一种叫做 Exclusions.

的东西

摘自文档:

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.

这里是 link,也许它可以帮助您在 pom.xml 中实现配置 --> Maven Exclusions

这是一个 Java 问题,没有其他技术如 OSGi

无法解决