工作记录】Found Banned Dependency: commons"/>
【工作记录】Found Banned Dependency: commons
【问题概述】
在使用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]
从这句“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>
之后重新编译,成功了。
更多推荐
【工作记录】Found Banned Dependency: commons
发布评论