我有一个依赖于HTTP BUilder的项目,这给了我后续的依赖树:
[INFO] +- org.codehaus.groovy.modules.http-builder:http-builder:jar:0.5.1:compile
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.3.2:compile
[INFO] | | \- commons-codec:commons-codec:jar:1.6:compile
[INFO] | +- net.sf.json-lib:json-lib:jar:jdk15:2.3:compile
[INFO] | | +- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] | | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | | +- commons-lang:commons-lang:jar:2.4:compile
[INFO] | | \- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
[INFO] | +- net.sourceforge.nekohtml:nekohtml:jar:1.9.9:compile
[INFO] | | \- xerces:xercesImpl:jar:2.8.1:compile
[INFO] | | \- xml-apis:xml-apis:jar:1.3.03:compile
[INFO] | \- xml-resolver:xml-resolver:jar:1.2:compile
Run Code Online (Sandbox Code Playgroud)
在我添加hibernate-entitymanager后,xml-apis:aml-apis更改版本.突然,Maven更喜欢使用版本1.0b2,这是dom4j的传递依赖:
[INFO] +- org.hibernate:hibernate-entitymanager:jar:4.3.1.Final:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] | +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] | +- org.hibernate:hibernate-core:jar:4.3.1.Final:compile
[INFO] | | +- antlr:antlr:jar:2.7.7:compile
[INFO] | | \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | | \- xml-apis:xml-apis:jar:1.0.b2:compile
Run Code Online (Sandbox Code Playgroud)
因此,我现在在运行时遇到以下异常:
java.lang.IncompatibleClassChangeError:
Class org.apache.xerces.parsers.AbstractSAXParser$LocatorProxy
does not implement the requested interface org.xml.sax.Locator
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过在我的pom.xml中手动添加具有良好版本号的依赖项来修复它,但我想知道为什么需要这样做:
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.3.03</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
默认情况下,当在依赖关系树中找到相同的依赖关系时,Maven使用最接近的根.
在你的情况下,这意味着
org.hibernate:hibernate-entitymanager:jar:4.3.1.Final:compile
\- dom4j:dom4j:jar:1.6.1:compile
\- xml-apis:xml-apis:jar:1.0.b2:compile
Run Code Online (Sandbox Code Playgroud)
VS
org.codehaus.groovy.modules.http-builder:http-builder:jar:0.5.1:compile
\- net.sourceforge.nekohtml:nekohtml:jar:1.9.9:compile
\- xerces:xercesImpl:jar:2.8.1:compile
\- xml-apis:xml-apis:jar:1.3.03:compile
Run Code Online (Sandbox Code Playgroud)
或者用另一种方式来说,3级深度比4级深,所以1.0.b2获胜.
要解决这个问题,要么排除xml-apis依赖关系,hibernate-entitymanager要么明确声明依赖关系xml-apis(尽管你可能不得不使用它,但Xerces及其依赖关系可能是一个噩梦,以获得版本对齐).
| 归档时间: |
|
| 查看次数: |
1317 次 |
| 最近记录: |