maven命令排除jar包冲突(简单高效)

maven命令排除jar包冲突(简单高效)

导语

在开发中,遇到jar包冲突时再正常不过的事了,有的时候,因为一点小问题,就要耽误很长的时间,严重影响开发效率,本文是通过maven命令排除jar包冲突,简单高效。

正文

好了,废话不多说,直接上干货。

使用命令:

mvn dependency:tree -Dverbose | grep 'omitted for conflict with'

通过此命令可以查找到存在冲突的jar包。

在windows中,还可以输入:

mvn dependency:tree -Dverbose | find 'omitted for conflict with'

如果已经知道了存在冲突的jar包,直接输入(比如是 log4j ):

mvn dependency:tree -Dverbose -Dincludes=log4j:log4j

然后具体查看pom文件,修改冲突的包。

如果是两个不同的jar包依赖的包里面的可以用exclusionsexclusion标签来进行剔除。

比如:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>4.3.14.RELEASE</version>
    <exclusions>
        <exclusion>
            <artifactId>commons-logging</artifactId>
            <groupId>commons-logging</groupId>
        </exclusion>
    </exclusions>
</dependency>

小结

本篇文章简单介绍了使用maven命令排除jar包冲突,由于纯手打,难免会有纰漏,如果发现错误的地方,请第一时间告诉我,这将是我进步的一个很重要的环节。

原创文章 59 获赞 287 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_45124488/article/details/102969138