当前位置:   article > 正文

Java学习笔记之二:Maven中依赖使用exclusions设置,来解决依赖冲突_java exclusions

java exclusions

一、依赖冲突产生的原因

调用的某个A包依赖于B包,B又依赖于C 和D 但是C依赖于E的1.0版本,D依赖于E的2.0版本  1.0跟2.0冲突了。

常见解决办法:直接使用2.0版本,删除1.0的依赖

原因:正常开源是向下依赖的,也就是说新版本都是包含老版本内容的。所以一般都可以直接使用2.0,这样1.0的依赖就需要我们手工把他干掉,这样就不冲突啦

二、CDM命令行:

2.1查看依赖树

进入到项目路径,输入依赖树命令

E:\Develop\eclipse\workspace\oa-organ>mvn dependency:tree

返回如下:

  1. ...
  2. Downloaded from aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/shared/maven-invoker/2.0.11/maven-invoker-2.0.11.jar (29 kB at 12 kB/s)
  3. Downloaded from aliyun: http://maven.aliyun.com/nexus/content/groups/public/commons-lang/commons-lang/2.6/commons-lang-2.6.jar (284 kB at 115 kB/s)
  4. [INFO] com.xxxx.oa:oa-organ:jar:1.0.0-SNAPSHOT
  5. [INFO] +- org.springframework:spring-core:jar:3.2.8.RELEASE:compile
  6. [INFO] | \- commons-logging:commons-logging:jar:1.1.3:compile
  7. [INFO] +- org.springframework:spring-webmvc:jar:3.2.8.RELEASE:compile
  8. [INFO] | +- org.springframework:spring-beans:jar:3.2.8.RELEASE:compile
  9. [INFO] | \- org.springframework:spring-expression:jar:3.2.8.RELEASE:compile
  10. [INFO] +- org.springframework:spring-context:jar:3.2.8.RELEASE:compile
  11. [INFO] +- org.springframework:spring-context-support:jar:3.2.8.RELEASE:compile
  12. [INFO] +- org.springframework:spring-aop:jar:3.2.8.RELEASE:compile
  13. [INFO] | \- aopalliance:aopalliance:jar:1.0:compile
  14. [INFO] +- org.springframework:spring-aspects:jar:3.2.8.RELEASE:compile
  15. [INFO] | \- org.aspectj:aspectjweaver:jar:1.7.4:compile
  16. [INFO] +- org.springframework:spring-tx:jar:3.2.8.RELEASE:compile
  17. [INFO] +- org.springframework:spring-jdbc:jar:3.2.8.RELEASE:compile
  18. [INFO] +- org.springframework:spring-web:jar:3.2.8.RELEASE:compile
  19. [INFO] +- junit:junit:jar:4.13.2:test
  20. [INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
  21. [INFO] +- org.springframework:spring-test:jar:3.2.8.RELEASE:test
  22. [INFO] +- log4j:log4j:jar:1.2.12:compile
  23. [INFO] +- org.slf4j:slf4j-api:jar:1.6.6:compile
  24. [INFO] +- org.slf4j:slf4j-log4j12:jar:1.6.6:compile
  25. [INFO] +- org.mybatis:mybatis:jar:3.2.1:compile
  26. [INFO] +- org.mybatis:mybatis-spring:jar:1.2.0:compile
  27. [INFO] \- mysql:mysql-connector-java:jar:5.1.47:compile
  28. [INFO] ------------------------------------------------------------------------
  29. [INFO] BUILD SUCCESS
  30. [INFO] ------------------------------------------------------------------------
  31. [INFO] Total time: 39.332 s
  32. [INFO] Finished at: 2021-11-27T23:06:45+08:00
  33. [INFO] ------------------------------------------------------------------------

2.2 修改项目中的pom.xml文件

在原有的依赖dependency中增加如下

下面<exclusions></exclusions>中间这一段是新增的

  1. <!-- spring依赖 -->
  2.           <dependency>  
  3.             <groupId>org.springframework</groupId>  
  4.             <artifactId>spring-core</artifactId>  
  5.             <version>3.2.8.RELEASE</version>  
  6.                 <exclusions>
  7.                     <exclusion>
  8.                       <groupId>commons-logging</groupId>
  9.                       <artifactId>commons-logging</artifactId>
  10.                     </exclusion>
  11.                 </exclusions>
  12.         </dependency>  

2.3再次查看依赖树

E:\Develop\eclipse\workspace\oa-organ>mvn dependency:tree

返回如下

  1. [INFO] Scanning for projects...
  2. [INFO]
  3. [INFO] ------------------------< com.xxxx.oa:oa-organ >------------------------
  4. [INFO] Building oa-organ 1.0.0-SNAPSHOT
  5. [INFO] --------------------------------[ jar ]---------------------------------
  6. [INFO]
  7. [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ oa-organ ---
  8. [WARNING] The artifact xml-apis:xml-apis:jar:2.0.2 has been relocated to xml-apis:xml-apis:jar:1.0.b2
  9. [INFO] com.xxxx.oa:oa-organ:jar:1.0.0-SNAPSHOT
  10. [INFO] +- org.springframework:spring-core:jar:3.2.8.RELEASE:compile
  11. [INFO] +- org.springframework:spring-webmvc:jar:3.2.8.RELEASE:compile
  12. [INFO] | +- org.springframework:spring-beans:jar:3.2.8.RELEASE:compile
  13. [INFO] | \- org.springframework:spring-expression:jar:3.2.8.RELEASE:compile
  14. [INFO] +- org.springframework:spring-context:jar:3.2.8.RELEASE:compile
  15. [INFO] +- org.springframework:spring-context-support:jar:3.2.8.RELEASE:compile
  16. [INFO] +- org.springframework:spring-aop:jar:3.2.8.RELEASE:compile
  17. [INFO] | \- aopalliance:aopalliance:jar:1.0:compile
  18. [INFO] +- org.springframework:spring-aspects:jar:3.2.8.RELEASE:compile
  19. [INFO] | \- org.aspectj:aspectjweaver:jar:1.7.4:compile
  20. [INFO] +- org.springframework:spring-tx:jar:3.2.8.RELEASE:compile
  21. [INFO] +- org.springframework:spring-jdbc:jar:3.2.8.RELEASE:compile
  22. [INFO] +- org.springframework:spring-web:jar:3.2.8.RELEASE:compile
  23. [INFO] +- junit:junit:jar:4.13.2:test
  24. [INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
  25. [INFO] +- org.springframework:spring-test:jar:3.2.8.RELEASE:test
  26. [INFO] +- log4j:log4j:jar:1.2.12:compile
  27. [INFO] +- org.slf4j:slf4j-api:jar:1.6.6:compile
  28. [INFO] +- org.slf4j:slf4j-log4j12:jar:1.6.6:compile
  29. [INFO] +- org.mybatis:mybatis:jar:3.2.1:compile
  30. [INFO] +- org.mybatis:mybatis-spring:jar:1.2.0:compile
  31. [INFO] \- mysql:mysql-connector-java:jar:5.1.47:compile
  32. [INFO] ------------------------------------------------------------------------
  33. [INFO] BUILD SUCCESS
  34. [INFO] ------------------------------------------------------------------------
  35. [INFO] Total time: 0.938 s
  36. [INFO] Finished at: 2021-11-27T23:36:43+08:00
  37. [INFO] ------------------------------------------------------------------------

与上面对比

[INFO] +- org.springframework:spring-core:jar:3.2.8.RELEASE:compile

下面的这一行

[INFO] |  \- commons-logging:commons-logging:jar:1.1.3:compile

由于刚刚加了exclusions参数设置,导致commons-logging失效

实验成功

自训:学Java,每天进步一点点,年底达成初级。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/682246
推荐阅读
相关标签
  

闽ICP备14008679号