因爲公司在super-bom裏配置了檢查規則,build項目時遇到錯誤:spring
[ERROR] [XXX Enforcer Rules] find DuplicateClassesapache
Found in:
org.apache.logging.log4j:log4j-slf4j-impl:jar:2.6.2:compile
ch.qos.logback:logback-classic:jar:1.1.7:compile
Duplicate classes:
org/slf4j/impl/StaticMDCBinder.class
org/slf4j/impl/StaticMarkerBinder.class
org/slf4j/impl/StaticLoggerBinder.classspring-boot
我在pom裏並無直接引用logback-classic,看到這個錯誤就懵了,我在pom裏沒有引用這個啊。post
解決過程:ui
能夠經過IntelliJ Idea的包依賴查看找出是哪一個包依賴了logback-classic。操做:View->Tool Window->Maven Projects,這個按鈕:spa
能夠看到package依賴圖,可能會比較複雜、雜亂,Ctrl+F後能夠搜索到:.net
這篇博客有提到如何處理這個問題:http://blog.csdn.net/xudan1010/article/details/52890102,即便用excusions來排除spring-boot-starter對spring-boot-starter-logging的依賴,而後引入log4j-slf4j-impl3d
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency>
另能夠使用命令來看依賴:mvn dependency:tree | grep logcode