Путь к классу содержит несколько привязок SLF4J с Gradle

Я получаю следующую ошибку при сборке проекта Gralde:

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]

И мой файл сборки Gradle:

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'
}

1 ответ

Решение

Вы можете попытаться решить это через resolutionStrategy лайк:

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

См. Документацию: http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html

Но если вы читаете заметку на сайте SLF4J, там написано, что это всего лишь предупреждение: http://www.slf4j.org/codes.html

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.

Другие вопросы по тегам