Maven依赖冲突 [英] maven dependency clash

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

问题描述

在我的项目中,有2个库,每个库都依赖于XML解析类java.xml.parsers.DocumentBuilderFactory.这些库中的每一个都从不同的jar引用文件(一个是从名为xmlParserAPIs的jar中获取文件,另一个是从xml-apis-1.0.b2.jar中获取文件).不幸的是,这些文件中的每个文件都有不同的类版本,因此我看到了运行时错误,具体取决于它们的加载顺序.这两个xml jar都是第三方库的传递依赖项.有解决这个冲突的好方法吗?

In my project, there are 2 libraries, each of which depend on the XML parsing class java.xml.parsers.DocumentBuilderFactory. Each of these libraries reference the file from different jar (one gets it from a jar called xmlParserAPIs while another gets it from xml-apis-1.0.b2.jar). Unfortunately there are different versions of the class in each of these files so I am seeing runtime errors, depending on the order they are loaded. Both of these xml jars are transitive dependencies of 3rd party libraries. Is there a good way to handle this conflict?

我不确定这在处理问题上是否有所不同,但这仅在测试中发生,因为其中一个依赖项在测试范围内.

edit: I'm not sure if it makes a difference on how to handle the problem but this only happens in testing because one of the dependencies is in the test scope.

谢谢, 杰夫

推荐答案

(...)不幸的是,这些文件中的每个文件都有不同的类版本,因此我看到了运行时错误,具体取决于它们的加载顺序.

(...) Unfortunately there are different versions of the class in each of these files so I am seeing runtime errors, depending on the order they are loaded.

从理论上讲,xml-apis.jarxmlParserAPIs.jar(来自xerces2-j)是相同的JAR ,但名称不同,xmlParserAPIs.jar已弃用多年(请参见此消息一个).

In theory, xml-apis.jar and xmlParserAPIs.jar (from xerces2-j) are the same JARs but with different names, xmlParserAPIs.jar being deprecated for years (see this message and this one).

如果您的依赖项依赖于xml-apis.jar的不同且不兼容的版本,那么我会说这些依赖项是互斥的,换句话说是不兼容的,至少对于您正在使用的版本而言.唯一的解决方案是找到具有收敛依赖性的版本.

If your dependencies relies on different and incompatible versions of xml-apis.jar, I would say that these dependencies are mutually exclusive, in other words incompatible, at least for the versions you're using. The only solution would be to find versions with a converging dependency.

如果他们可以使用兼容版本,请使用依赖项

In case they could use compatible versions, use a dependency exclusion for xmlParserAPIs.jar to use xml-api.jar only.

我不确定这在处理问题上是否有所不同,但这仅在测试中发生,因为其中一个依赖项在测试范围内.

I'm not sure if it makes a difference on how to handle the problem but this only happens in testing because one of the dependencies is in the test scope.

不,这只是解释了为什么您在运行时没有遇到问题(因为test范围不在类路径上,并且显然不会发生冲突).

No, this just explains why you don't get the problem at runtime (because the test scoped is not on the classpath then and, obviously, doesn't conflict).

这篇关于Maven依赖冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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