类路径包含多个使用Gradle的SLF4J绑定

类路径包含多个使用Gradle的SLF4J绑定

本文介绍了类路径包含多个使用Gradle的SLF4J绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  SLF4J:类路径包含多个SLF4J绑定。 
SLF4J:在[jar:file:/Users/qliu/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.0.6/ba738848da3e6fffa0107771c75546eb6d407f3c/logback- classic-1.0.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J:在[jar:file:/Users/qliu/.gradle/caches/modules-2/files-2.1中找到绑定/uk.org.lidalia/slf4j-test/1.1.0/f4f523049e041dea673bd421d7b0d61fb5e49548/slf4j-test-1.1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J:请参阅http:// www .slf4j.org / codes.html#multiple_bindings进行说明。
SLF4J:实际绑定类型为[ch.qos.logback.classic.selector.DefaultContextSelector]



 依赖关系{
//用于输出记录器消息
编译组:'log4j',名称:'log4j',版本:'1.2.17'

//用于测试输出记录器消息
编译组:'uk.org.lidalia',名称:'slf4j-test',版本:'1.1.0'
}


解决方案

您可以尝试通过 resolutionStrategy 来解决它:

  configurations.all {
resolutionStrategy.eachDependency {DependencyResolveDetails details - >
if(details.requested.name =='log4j'){
details.useTarget'log4j:log4j:1.2。+'
}
}
}

请参阅文档:



SLF4J发出的警告就是这个警告。即使存在多个绑定,SLF4J也会选择一个日志框架/实现并绑定它。


I am getting the following error when I build my Gralde project:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/qliu/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.0.6/ba738848da3e6fffa0107771c75546eb6d407f3c/logback-classic-1.0.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/qliu/.gradle/caches/modules-2/files-2.1/uk.org.lidalia/slf4j-test/1.1.0/f4f523049e041dea673bd421d7b0d61fb5e49548/slf4j-test-1.1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.selector.DefaultContextSelector]

And my Gradle build file:

dependencies {
        // for output logger messages
        compile group: 'log4j', name: 'log4j', version: '1.2.17'

        // for testing outputed logger messages
        compile group: 'uk.org.lidalia', name: 'slf4j-test', version: '1.1.0'
}
解决方案

You could try to solve it via resolutionStrategy like:

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.name == 'log4j') {
            details.useTarget 'log4j:log4j:1.2.+'
        }
    }
}

See the documentation: http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html

But if you read the note in the SLF4J site it says that it's just a warning:http://www.slf4j.org/codes.html#multiple_bindings

The warning emitted by SLF4J is just that, a warning. Even when multiple bindings are present, SLF4J will pick one logging framework/implementation and bind with it.

这篇关于类路径包含多个使用Gradle的SLF4J绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 13:55