Maven解决类包依赖冲突_commons-lang:commons-lang:2.3 conflict with 2.5(ma-程序员宅基地

技术标签: maven 解决冲突  maven  

使用maven最烦人的可能就是类包之间的版本冲突引发的问题了,类包冲突的一个很大的原因即产类包之间的间接依赖引起的。每个显式声明的类包都会依赖于一些其它的隐式类包,这些隐式的类包会被maven间接引入进来,因而可能造成一个我们不想要的类包的载入,严重的甚至会引起类包之间的冲突。 

要解决这个问题,首先就是要查看pom.xml显式和隐式的依赖类包,然后通过这个类包树找出我们不想要的依赖类包,手工将其排除在外就可以了。 

下面,通过一个例子来说明: 

我的项目使用testng进行测试,使用了untilis,由于unitils的类包会隐式依赖于junit,这是我不想看到的,下面的目的就是找出junit会谁隐式载入了,然后exculte掉它。 


通过idea的maven依赖分析将不需要的依赖exclude掉 


打开maven的pom.xml,在某个<dependency>中通过右键菜单:maven->show dependency 打开分析的图形化页面,如下所示: 



通过菜单的exclude即解决这个间接依赖。 

通过这个依赖树,我们还可以看到Junit还通过“unitils-spring”的依赖间接载入了,如下所示: 



从上面的依赖树中,我们可以看出junit通过unitils-spring的unitils-database间接引入了,由于我的项目都不需要数据库的测试,因此,可以把unitils-database项整个exclude掉。 

下面,是处理完成后的pom.xml关键片断: 

Xml代码  收藏代码

  1.     <dependency>  

  2.         <groupId>org.unitils</groupId>  

  3.         <artifactId>unitils-testng</artifactId>  

  4.         <version>${unitils.version}</version>  

  5.         <scope>test</scope>  

  6.         <exclusions>  

  7.             <exclusion>  

  8.                 <artifactId>junit</artifactId>  

  9.                 <groupId>junit</groupId>  

  10.             </exclusion>  

  11.         </exclusions>  

  12.   

  13.     </dependency>  

  14.   

  15.     <dependency>  

  16.         <groupId>org.unitils</groupId>  

  17.         <artifactId>unitils-spring</artifactId>  

  18.         <version>${unitils.version}</version>  

  19.         <scope>test</scope>  

  20.         <exclusions>  

  21.             <exclusion>  

  22.                 <artifactId>unitils-database</artifactId>  

  23.                 <groupId>org.unitils</groupId>  

  24.             </exclusion>  

  25.         </exclusions>  

  26.     </dependency>  

  27. </dependencies>  



这样,被间接隐式引入的junit就被我们exclude在外了。 


有时通过idea的依赖分析工具产生的树不够全,这时就需要使用mvn dependency:tree来查看依赖树了。 
通过mvn dependency:tree 查看依赖树 


引用

mvn dependency:tree



以下是使用这个工具产生的依赖树: 

引用

E:\01workspace\chenxh\09research\rop\rop>mvn dependency:tree 
[WARNING] 
[WARNING] Some problems were encountered while building the effective settings 
[WARNING] 'pluginRepositories.pluginRepository.id' must not be 'local', this identifier is reserved for the local re 
tory, using it for other repositories will corrupt your repository metadata. @ C:\Users\Administrator\.m2\settings.x 
[WARNING] 
[INFO] Scanning for projects... 
[INFO] 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building rop 1.0-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ rop --- 
[INFO] com.rop:rop:jar:1.0-SNAPSHOT 
[INFO] +- javax.validation:validation-api:jar:1.0.0.GA:compile 
[INFO] +- org.hibernate:hibernate-validator:jar:4.2.0.Final:compile 
[INFO] +- org.codehaus.jackson:jackson-core-asl:jar:1.9.5:compile 
[INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.5:compile 
[INFO] +- org.codehaus.jackson:jackson-jaxrs:jar:1.9.5:compile 
[INFO] +- org.codehaus.jackson:jackson-xc:jar:1.9.5:compile 
[INFO] +- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.0.0-RC2:compile 
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.0.0-RC2:compile 
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.0.0-RC2:compile 
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.0.0-RC2:compile 
[INFO] |  +- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.0.0-RC2:compile 
[INFO] |  \- org.codehaus.woodstox:stax2-api:jar:3.1.1:compile 
[INFO] |     \- javax.xml.stream:stax-api:jar:1.0-2:compile 
[INFO] +- org.slf4j:slf4j-api:jar:1.6.1:compile 
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.6.1:compile 
[INFO] +- log4j:log4j:jar:1.2.16:compile 
[INFO] +- org.springframework:spring-core:jar:3.1.1.RELEASE:compile 
[INFO] |  +- org.springframework:spring-asm:jar:3.1.1.RELEASE:compile 
[INFO] |  \- commons-logging:commons-logging:jar:1.1.1:compile 
[INFO] +- org.springframework:spring-context:jar:3.1.1.RELEASE:compile 
[INFO] |  +- org.springframework:spring-aop:jar:3.1.1.RELEASE:compile 
[INFO] |  +- org.springframework:spring-beans:jar:3.1.1.RELEASE:compile 
[INFO] |  \- org.springframework:spring-expression:jar:3.1.1.RELEASE:compile 
[INFO] +- org.springframework:spring-context-support:jar:3.1.1.RELEASE:compile 
[INFO] +- org.springframework:spring-web:jar:3.1.1.RELEASE:compile 
[INFO] |  \- aopalliance:aopalliance:jar:1.0:compile 
[INFO] +- org.springframework:spring-test:jar:3.1.1.RELEASE:compile 
[INFO] +- org.springframework:spring-webmvc:jar:3.1.1.RELEASE:compile 
[INFO] +- org.testng:testng:jar:6.3:test 
[INFO] |  +- org.beanshell:bsh:jar:2.0b4:test 
[INFO] |  +- com.beust:jcommander:jar:1.12:test 
[INFO] |  \- org.yaml:snakeyaml:jar:1.6:test 
[INFO] +- org.mockito:mockito-all:jar:1.8.5:test 
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided 
[INFO] +- org.unitils:unitils-core:jar:3.3:test 
[INFO] |  +- commons-lang:commons-lang:jar:2.3:test 
[INFO] |  +- commons-collections:commons-collections:jar:3.2:test 
[INFO] |  \- ognl:ognl:jar:2.6.9:test 
[INFO] +- org.unitils:unitils-testng:jar:3.3:test 
[INFO] |  \- org.testng:testng:jar:jdk15:5.8:test 
[INFO] |     \- junit:junit:jar:3.8.1:test 
[INFO] \- org.unitils:unitils-spring:jar:3.3:test 
[INFO]    +- org.springframework:spring-tx:jar:2.5.2:test 
[INFO]    \- org.unitils:unitils-database:jar:3.3:test 
[INFO]       +- org.unitils:unitils-dbmaintainer:jar:3.3:test 
[INFO]       |  +- org.hibernate:hibernate:jar:3.2.5.ga:test 
[INFO]       |  |  +- net.sf.ehcache:ehcache:jar:1.2.3:test 
[INFO]       |  |  +- asm:asm-attrs:jar:1.5.3:test 
[INFO]       |  |  +- dom4j:dom4j:jar:1.6.1:test 
[INFO]       |  |  +- antlr:antlr:jar:2.7.6:test 
[INFO]       |  |  +- cglib:cglib:jar:2.1_3:test 
[INFO]       |  |  \- asm:asm:jar:1.5.3:test 
[INFO]       |  \- org.dbunit:dbunit:jar:2.2.2:test 
[INFO]       |     +- junit-addons:junit-addons:jar:1.4:test 
[INFO]       |     |  +- xerces:xercesImpl:jar:2.6.2:test 
[INFO]       |     |  \- xerces:xmlParserAPIs:jar:2.6.2:test 
[INFO]       |     +- poi:poi:jar:2.5.1-final-20040804:test 
[INFO]       |     \- org.slf4j:slf4j-nop:jar:1.4.3:test 
[INFO]       +- commons-dbcp:commons-dbcp:jar:1.2.2:test 
[INFO]       |  \- commons-pool:commons-pool:jar:1.3:test 
[INFO]       \- org.springframework:spring-jdbc:jar:2.5.2:test 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 8.250s 
[INFO] Finished at: Fri Jun 08 09:08:09 CST 2012 
[INFO] Final Memory: 7M/245M 
[INFO] ------------------------------------------------------------------------ 



我原来一个使用idea分析不出的隐式依赖就是通用mvn dependency:tree找到的。

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u011490072/article/details/80652160

智能推荐

我的一个关于文件的程序 - [C语言]_fseek(fp,0l,2)-程序员宅基地

文章浏览阅读6.3k次。 2005-09-05我的一个关于文件的程序 - [C语言]#includevoid main(){char ch;FILE* fp;if((fp=fopen("test.txt","r"))==NULL){printf("error");exit(1);}fseek(fp,0L,2);while((fseek(fp,-1L,1))!=-1){ch=fgetc(fp);pu_fseek(fp,0l,2)

oracle 设置查询条数,SQL、MySQL、Oracle、 Sqlite、Informix数据库查询指定条数数据的方法...-程序员宅基地

文章浏览阅读674次。SQL查询前10条的方法为:select top X * from table_name--查询前X条记录,可以改成需要的数字,比如前10条。select top X * from table_name order by colum_name desc--按colum_name属性降序排序查询前X条记录,“order by” 后紧跟要排序的属性列名,其中desc表示降序,asc表示升序(默认也..._oracle怎么用语句设置查询结果数量

课程设计之第二次冲刺----第九天-程序员宅基地

文章浏览阅读58次。讨论成员:罗凯旋、罗林杰、吴伟锋、黎文衷讨论完善APP,调试功能。转载于:https://www.cnblogs.com/383237360q/p/5011594.html

favicon.ico 图标及时更新问题_win 软件开发 ico图标多久更新-程序员宅基地

文章浏览阅读5.4k次。首先看你 favicon.ico 图标文件引入路径是否正确然后 看ico文件能否正常打开,这两个没问题的话,在地址栏直接输入你的域名 http://xxx.com/favicon.ico 注意 此刻可能还是 之前的ico图标 不要着急 刷新一下 试试 完美解决 清除程序缓存_win 软件开发 ico图标多久更新

手工物理删除Oracle归档日志RMAN备份报错_rman 说明与资料档案库中在任何归档日志都不匹配-程序员宅基地

文章浏览阅读2.1k次。Oracle归档日志删除我们都都知道在controlfile中记录着每一个archivelog的相关信息,当然们在OS下把这些物理文件delete掉后,在我们的controlfile中仍然记录着这些archivelog的信息,在oracle的OEM管理器中有可视化的日志展现出,当我们手工清除 archive目录下的文件后,这些记录并没有被我们从controlfile中清除掉,也就是or_rman 说明与资料档案库中在任何归档日志都不匹配

命令提示符_命令提示符文件开头-程序员宅基地

文章浏览阅读706次。命令提示符:[ root@localhost桌面] #[用户名@主机名 当前所在位置] #(超级用户) KaTeX parse error: Expected 'EOF', got '#' at position 25: …用户: #̲ su 用户名 //切… su密码:[ root@cml桌面] #临时提升为root权限:# sudo 命令..._命令提示符文件开头

随便推点

android+打包+不同app,基于Gradle的Android应用打包实践-程序员宅基地

文章浏览阅读152次。0x01 基本项目结构使用Android Studio创建的Android项目会划分成三个层级:project : settings.gradle定义了构建应用时包含了哪些模块;build.gradle定义了适用于项目中所有模块的构建配置module : 可以是一个app类型的module,对应生成apk应用;也可以是一个lib类型的module,对应生成aar包. 每个module中包含的bui..._android多个应用 gradle 怎么打包指定的应用

qsort实现顺序与逆序/排整型,字符串数组,字符数组,结构体类型数组的名字排序,年龄排序等_qsort反向排序-程序员宅基地

文章浏览阅读599次,点赞12次,收藏11次。前言:通常我们排序都需要创建一个函数实现排序,但当我们排完整型数组时,想要排字符串呢?那需要重新创建一个函数,完善它的功能,进而实现排字符串,这样非常繁琐,但是有一个函数可以帮我们实现传什么,排什么;qsort的传参:(1️⃣,2️⃣,3️⃣,4️⃣) (首元素地址,排序的元素个数,每个元素的大小,指向比较两个元素的函数的指针)1️⃣2️⃣3️⃣4️⃣的传参方法,下面介绍:…整型数组:......_qsort反向排序

MVC绕过登陆界面验证时HttpContext.Current.User.Identity.Name取值为空问题解决方法_mvc 不验证登陆-程序员宅基地

文章浏览阅读355次。MVC绕过登陆界面验证时HttpContext.Current.User.Identity.Name取值为空问题解决方法_mvc 不验证登陆

Java中DO、DTO、BO、AO、VO、POJO、Query 命名规范_dto命名规范-程序员宅基地

文章浏览阅读7.6k次,点赞2次,收藏8次。1.分层领域模型规约: • DO( Data Object):与数据库表结构一一对应,通过DAO层向上传输数据源对象。 • DTO( Data Transfer Object):数据传输对象,Service或Manager向外传输的对象。 • BO( Business Object):业务对象。 由Service层输出的封装业务逻辑的对象。 • AO( Ap..._dto命名规范

1015. Reversible Primes (20) PAT甲级刷题_pat甲级1015-程序员宅基地

文章浏览阅读91次。A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a pr..._pat甲级1015

ABAP接口之Http发送json报文_abap http 转换为json输出-程序员宅基地

文章浏览阅读1.5k次。ABAP接口之Http发送json报文abap 调用http 发送 json 测试函数SE11创建结构:zsmlscpnoticeSE37创建函数:zqb_test_http_fuc1FUNCTIONzqb_test_http_fuc1.*"----------------------------------------------------------------..._abap http 转换为json输出