在项目中好几次出现jar包冲突的情况,想要使用idea查看依赖关系很不方便,第一是慢,第二是搜索不方便。在网络上很多都是这种办法,但今天我找到了一个更好更简洁的办法。
1 可以在idea中右击项目
输入mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ----< org.springframework.boot:xxl-job-executor-sample-springboot >-----
[INFO] Building xxl-job-executor-sample-springboot 1.5.9.RELEASE
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ xxl-job-executor-sample-springboot ---
[INFO] org.springframework.boot:xxl-job-executor-sample-springboot:war:1.5.9.RELEASE
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.5.9.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:1.5.9.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:1.5.9.RELEASE:compile
[INFO] | | - org.yaml:snakeyaml:jar:1.17:runtime
[INFO] | +- org.hibernate:hibernate-validator:jar:5.3.6.Final:compile
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
[INFO] | | - com.fasterxml:classmate:jar:1.3.4:compile
...........
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.123 s
[INFO] Finished at: 2020-03-13T15:09:15+08:00
[INFO] ------------------------------------------------------------------------
上面就是jar包的依赖关系,如果想要查找某个jar包冲突,就ctr+f查找就可以。如果某个包依赖另一个jar包(A),而后者(A)与我们想要使用的jar包冲突,我们就要去除A jar包,可以使用
<dependency>
<groupId>com.baidu.disconf</groupId>
<artifactId>disconf-client</artifactId>
<version>2.6.36</version>
<!--去除disconf中我们不需要的依赖包-->
<exclusions>
<exclusion>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
</exclusion>
</exclusions>
</dependency>
2 也可以直接到项目文件夹中使用cmd查看依赖包,打开项目文件夹,shift+鼠标右键
打开cmd命令同样输入mvn dependency:tree
即可。