13.4 库依赖冲突问题:Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path

13.4 库依赖冲突问题:Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path

问题描述

引入第三方库'org.raml:raml-parser:0.8.12',导致slf4j依赖冲突。

java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path

错误日志

Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.
    at org.slf4j.impl.Log4jLoggerFactory.<clinit>(Log4jLoggerFactory.java:54)
    ... 11 more
:bootRun FAILED

Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path

classpath jar包冲突

gradle -q app:dependencies

依赖树分析

解决方案

排除冲突的依赖:

Maven:

<exclusions> 
<exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId></exclusion>
 <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion>
</exclusions> 

Gradle:

compile('org.raml:raml-parser:0.8.12'){
        exclude module: 'slf4j-log4j12'
        exclude module: 'log4j'
}

参考资料:
https://docs.gradle.org/current/userguide/userguide_single.html#sec:listing_dependencies

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容