解决Maven中库的不兼容版本的依赖关系 [英] Resolving dependencies of incompatible versions of a library in Maven

查看:792
本文介绍了解决Maven中库的不兼容版本的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

问题的一个例子

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

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

第一个模块MA包含主类和它取决于MB和MC

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

MB模块取决于LA v2。

MB module depends on LA v2.

MC模块取决于LB版本。

MC module depends on LB version.

LB版本取决于LA v1。

LB version depends on LA v1.

最后,依赖树如下:

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


推荐答案

我不知道你是否考虑过。在Maven中存在一个名为排除的东西。

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

从文档中提取:


由于maven 2.x可传递地解析依赖关系,因此
不需要的依赖项可能包含在项目的类路径中。
例如,您所依赖的项目可能没有正确声明其
依赖项集。为了解决这个特殊的
状态,maven 2.x已经引入了显式
依赖性排除的概念。排除是根据您的POM
中的特定依赖项设置的,并且针对特定的groupId和artifactId。当您构建项目
时,该工件将不会通过声明排除
的依赖项添加到
项目的类路径中。

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.

在这里链接,也许它可以帮助你在pom.xml中实现配置 - > Maven Exclusions

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

这篇关于解决Maven中库的不兼容版本的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆