【工作记录】Found Banned Dependency: commons-logging:commons-logging 依赖冲突解决

【问题概述】

     在使用maven构建项目的时候,偶尔会遇到jar包依赖冲突的问题,比如:

[WARNING] Rule 2: org.apache.maven.plugins.enforcer.BannedDependencies failed with message:
Found Banned Dependency: commons-logging:commons-logging:jar:1.1.3
Use 'mvn dependency:tree' to locate the source of the banned dependencies.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 45.682 s
[INFO] Finished at: 2018-07-11T19:31:20+08:00
[INFO] Final Memory: 54M/487M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.1.1:enforce (enforce-banned-dependencies) on project fcarXXX: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

     从这句“Found Banned Dependency: commons-logging:commons-logging:jar:1.1.3”可知,冲突的包是commons-logging。


【解决思路】

     1.遇到maven依赖冲突,首先想到的是通过依赖树来查看冲突,命令为“mvn dependency:tree”。

       

     如图,dos命令下查看的项目依赖太多了,直接依赖和传递依赖看的眼花缭乱,项目较大的话,排查版本冲突的jar很困难。幸好IDEA可以通过可视化工具来检查项目jar包的依赖关系。


    2.IDEA可视化查看jar包依赖关系

    点击“Maven Project” -> “Show Dependencies”按钮:

      

       其中的红线代表有冲突,最左侧代表项目,如图,虽然可视化了,但是依赖的jar太多了,红线也很多,还是没有定位到控制台中提示的“Commons-logging:1.1.3”,试着选中可疑的几个jar,右击“Exclude”,之后重新Compile,仍然报错。不太好用。


      3."-Dverbose -Dincludes"附加条件定位问题

      尝试了上述2中方案,都不是很理想能解决我的问题,之后在文档中看到“mvn dependency:tree”命令可以做模糊或者精确的匹配:

mvn dependency:tree -Dverbose -Dincludes=“xxx”

       重新尝试了之后,发现对"Commons-logging 1.1.3"的传递依赖,如图:

      

      发现这个传递依赖是由于我的pom中dependency了“base-dao-es”这个jar,之后对它做exclude操作:

<dependency>
	<groupId>com.XXX.XXX</groupId>
	<artifactId>base-dao-es</artifactId>
	<version>${framework.version}</version>
	<exclusions>
		<exclusion>
			<artifactId>commons-logging</artifactId>
			<groupId>commons-logging</groupId>
		</exclusion>
	</exclusions>
</dependency>
        之后重新编译,成功了。




  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值