Warning maven relocated xml-apis to 1.0.b

maven 依赖

在maven项目中,一些基础的jar包被引用多次是很常见的事情。maven选择jar的版本是基于
- 依赖深度浅的 比如C项目依赖xml.jar。C依赖的B也引入了xml.jar。那么优先选择C中指定的
- 如果依赖深度一样,第一次依赖的jar被选中

实际项目开发,一般是exclude掉B项目中的xml.jar,在C项目中显示指定xml.jar的版本。

<dependency>
    <groupId></groupId>
    <artifactId>test</artifactId>
    <version>1.0</version>
    <exclusions>
        <exclusion>
            <groupId>xml</group>
            <artifactId>xml</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>xml</group>
    <artifactId>xml</artifactId>
    <version> 2.2</version>
</dependency>

问题

按照上面的原则对xml-apis.1.0.b进行升级到xml-apis.1.4。但是始终exclude不出去xml-apis1.0.b
mvn dependency:tree

看到xml-apis.1.0.的来源已经不是依赖的项目中引入的,而是在根路径下。

这个颠覆了对maven的认知。

这里写图片描述

看了下xml-apis这个,就知道版本有多混乱了,2.0.2的比1.4的还要先发布。

解决

直接引入了xerces xercesImpl 2.10.0.这个jar包中有xml-apis1.4.01版本

<dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.10.0</version>
</dependency>

参考

http://javamoods.blogspot.com/2009/06/maven-how-relocated-artifacts-can-ruin.html
https://stackoverflow.com/questions/11677572/dealing-with-xerces-hell-in-java-maven?answertab=votes
https://gxnotes.com/article/29548.html

猜你喜欢

转载自blog.csdn.net/fs1360472174/article/details/74044426