maven排查冲突jar包

清疚 2022-05-08 11:44 337阅读 0赞

1. 问题描述

使用maven可以非常方便的管理我们项目的各种依赖,但是也存在着一些问题。当我们在pom.xml文件中引入新的jar包,那么该jar包依赖的其它jar包也会自动被下载。如果这些自动下载的jar包和项目中已存在的jar包版本不一致,那么就会造成jar包版本的冲突。


2. 解决方法

我们可以使用mvn命令来排查项目中存在版本冲突的jar包。

  • 首先,在命令行跳转到当前项目路径(如果使用Idea等工具,可以直接在终端Terminal中运行mvn命令),为了便于查找我们可以把依赖关系写入一个临时文本文件tree.txt。

    1. mvn dependency:tree -Dverbose > tree.txt
  • 然后,打开生成的tree.txt文件,全局搜索”conflict”关键字,即可找到版本冲突的jar包。

    1. [INFO] +- io.springfox:springfox-swagger2:jar:2.6.1:compile
    2. [INFO] | +- io.swagger:swagger-annotations:jar:1.5.10:compile
    3. [INFO] | +- io.swagger:swagger-models:jar:1.5.10:compile
    4. [INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.1:compile (version managed from 2.4.5)
    5. [INFO] | | +- (org.slf4j:slf4j-api:jar:1.7.21:compile - version managed from 1.7.10; omitted for duplicate)
    6. [INFO] | | \- (io.swagger:swagger-annotations:jar:1.5.10:compile - omitted for duplicate)
    7. [INFO] | +- io.springfox:springfox-spi:jar:2.6.1:compile
    8. [INFO] | | \- io.springfox:springfox-core:jar:2.6.1:compile
    9. [INFO] | | +- (com.google.guava:guava:jar:18.0:compile - omitted for duplicate)
    10. [INFO] | | +- (com.fasterxml:classmate:jar:1.3.1:compile - omitted for duplicate)
    11. [INFO] | | +- (org.slf4j:slf4j-api:jar:1.7.21:compile - version managed from 1.6.3; omitted for duplicate)
    12. [INFO] | | +- (org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile - omitted for duplicate)
    13. [INFO] | | \- (org.springframework.plugin:spring-plugin-metadata:jar:1.2.0.RELEASE:compile - omitted for duplicate)
    14. [INFO] | +- io.springfox:springfox-schema:jar:2.6.1:compile
    15. [INFO] | | +- (io.springfox:springfox-core:jar:2.6.1:compile - omitted for duplicate)
    16. [INFO] | | \- (io.springfox:springfox-spi:jar:2.6.1:compile - omitted for duplicate)
    17. [INFO] | +- io.springfox:springfox-swagger-common:jar:2.6.1:compile
    18. [INFO] | | +- (io.swagger:swagger-annotations:jar:1.5.10:compile - omitted for duplicate)
    19. [INFO] | | +- (io.swagger:swagger-models:jar:1.5.10:compile - omitted for duplicate)
    20. [INFO] | | +- (io.springfox:springfox-spi:jar:2.6.1:compile - omitted for duplicate)
    21. [INFO] | | +- (io.springfox:springfox-schema:jar:2.6.1:compile - omitted for duplicate)
    22. [INFO] | | +- (io.springfox:springfox-spring-web:jar:2.6.1:compile - omitted for duplicate)
    23. [INFO] | | +- (com.google.guava:guava:jar:18.0:compile - omitted for duplicate)
    24. [INFO] | | +- (com.fasterxml:classmate:jar:1.3.1:compile - omitted for duplicate)
    25. [INFO] | | +- (org.slf4j:slf4j-api:jar:1.7.21:compile - version managed from 1.7.10; omitted for duplicate)
    26. [INFO] | | +- (org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile - omitted for duplicate)
    27. [INFO] | | \- (org.springframework.plugin:spring-plugin-metadata:jar:1.2.0.RELEASE:compile - omitted for duplicate)
    28. [INFO] | +- io.springfox:springfox-spring-web:jar:2.6.1:compile
    29. [INFO] | | +- (com.google.guava:guava:jar:18.0:compile - omitted for duplicate)
    30. [INFO] | | +- (com.fasterxml:classmate:jar:1.3.1:compile - omitted for duplicate)
    31. [INFO] | | +- (org.slf4j:slf4j-api:jar:1.7.21:compile - version managed from 1.7.10; omitted for duplicate)
    32. [INFO] | | +- (org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile - omitted for duplicate)
    33. [INFO] | | +- (org.springframework.plugin:spring-plugin-metadata:jar:1.2.0.RELEASE:compile - omitted for duplicate)
    34. [INFO] | | \- (io.springfox:springfox-spi:jar:2.6.1:compile - omitted for duplicate)
    35. [INFO] | +- (com.google.guava:guava:jar:18.0:compile - omitted for ---<conflict 关键字>--- with 15.0)
    36. [INFO] | +- com.fasterxml:classmate:jar:1.3.1:compile
    37. [INFO] | +- org.slf4j:slf4j-api:jar:1.7.21:compile

发表评论

表情:
评论列表 (有 0 条评论,337人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Maven Jar冲突解决方案

    Maven Jar包冲突解决方案 在Java开发中,使用Maven作为依赖管理工具是非常常见的。然而,有时候在项目中使用不同的依赖项时可能会遇到冲突的情况。本文将为您介绍如何

    相关 maven排查冲突jar

    1. 问题描述 使用maven可以非常方便的管理我们项目的各种依赖,但是也存在着一些问题。当我们在pom.xml文件中引入新的jar包,那么该jar包依赖的其它jar包也

    相关 解决Maven依赖jar冲突总结

    maven导入jar包中的一些概念: 直接依赖:项目中直接导入的jar包,就是该项目的直接依赖包。 传递依赖:项目中没有直接导入的jar包,可以通过项目直接依赖jar包

    相关 maven解决jar冲突

    1. maven默认使用第一声明优先的原则,即谁先声明,就使用谁。这个声明的依赖包也是优先进入项目的。 2. 路径近者优先原则。jar包导入时分如下两种。直接依赖要比传递依