Definitive answer to slf4j and logback - classic transitive dependency

I was really struggling with loading logback-classic as a transitive dependency issue. I am following the advice found here on stackoverflow, but it keeps repeating.

I'm using maven exceptions to try and control it, it doesn't appear at all in my pom dependency hierarchy. And yet it still loads!

Here is my runtime trace

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/david/.m2/repository/de/ruedigermoeller/kontraktor-http/3.33/kontraktor-http-3.33.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/david/.m2/repository/ch/qos/logback/logback-classic/1.2.1/logback-classic-1.2.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
W 13:22:24:837 : DispatcherThread 1 : DispatcherThread : 
java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getLoggerFactoryClassStr()Ljava/lang/String;
at org.slf4j.LoggerFactory.reportActualBinding(LoggerFactory.java:271)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:143)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:120)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:331)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:283)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:304)
at org.quartz.impl.StdSchedulerFactory.<init>(StdSchedulerFactory.java:284)
at org.quartz.impl.StdSchedulerFactory.getDefaultScheduler(StdSchedulerFactory.java:1539)
at uk.co.example.ExampleEwsService.init(ExampleEwsService.java:296)

      

Part of the problem is that the Kontraktor structure overrides the StaticLoggerBinder.getLoggerFactoryClassStr method. But it's easy to make sure it loads first and then exclude the classic quartz log that loads it like this:

    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
        <version>2.2.3</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz-jobs</artifactId>
        <version>2.2.3</version>
    </dependency>

      

At this point, slf4j is only loaded by the contractor. logback-classic doesn't appear anywhere depending on: tree

[INFO] +- de.ruedigermoeller:kontraktor:jar:3.33:compile
[INFO] |  +- org.jctools:jctools-core:jar:1.0:compile
[INFO] |  \- de.ruedigermoeller:fst:jar:2.44.5:compile
[INFO] |     +- com.fasterxml.jackson.core:jackson-core:jar:2.5.3:compile
[INFO] |     +- org.javassist:javassist:jar:3.19.0-GA:compile
[INFO] |     +- org.objenesis:objenesis:jar:2.1:compile
[INFO] |     \- com.cedarsoftware:java-util:jar:1.9.0:compile
[INFO] |        \- com.cedarsoftware:json-io:jar:2.5.1:compile
[INFO] +- de.ruedigermoeller:kontraktor-http:jar:3.33:compile
[INFO] |  +- io.github.lukehutch:fast-classpath-scanner:jar:1.2.3:compile
[INFO] |  +- org.apache.httpcomponents:httpasyncclient:jar:4.1:compile
[INFO] |  |  +- org.apache.httpcomponents:httpcore:jar:4.4.1:compile
[INFO] |  |  +- org.apache.httpcomponents:httpcore-nio:jar:4.4.1:compile
[INFO] |  |  +- org.apache.httpcomponents:httpclient:jar:4.4.1:compile
[INFO] |  |  |  \- commons-codec:commons-codec:jar:1.9:compile
[INFO] |  |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  +- javax.websocket:javax.websocket-api:jar:1.1:compile
[INFO] |  +- io.undertow:undertow-core:jar:1.2.8.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.1.4.GA:compile
[INFO] |  |  +- org.jboss.xnio:xnio-api:jar:3.3.1.Final:compile
[INFO] |  |  \- org.jboss.xnio:xnio-nio:jar:3.3.1.Final:runtime
[INFO] |  +- io.undertow:undertow-websockets-jsr:jar:1.2.8.Final:compile
[INFO] |  |  +- io.undertow:undertow-servlet:jar:1.2.8.Final:compile
[INFO] |  |  |  +- org.jboss.spec.javax.servlet:jboss-servlet-api_3.1_spec:jar:1.0.0.Final:compile
[INFO] |  |  |  \- org.jboss.spec.javax.annotation:jboss-annotations-api_1.2_spec:jar:1.0.0.Final:compile
[INFO] |  |  \- org.jboss.spec.javax.websocket:jboss-websocket-api_1.1_spec:jar:1.1.0.Final:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.12:compile
[INFO] |  \- org.jsoup:jsoup:jar:1.8.2:compile
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.5:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.5:compile
[INFO] +- org.quartz-scheduler:quartz:jar:2.2.3:compile
[INFO] |  \- c3p0:c3p0:jar:0.9.1.1:compile
[INFO] +- org.quartz-scheduler:quartz-jobs:jar:2.2.3:compile

      

Such a simple question, how is logback-classic loaded and who is downloading it?

+3


source to share


1 answer


Darren Forsyth's comment is the answer. This -Dincludes = ch.qos.logback: logback-classic allowed me to find the dependency. It seems like the addiction: tree search is only that deep. -Dincludes searches the entire hierarchy for the specified dependency.



+3


source







All Articles