Billtaz
Billtaz

Reputation: 95

NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder with correct dependencies on Gradle

We are attempting to upgrade our logging. Using a gradle file we are updating these packages from :

    implementation "org.slf4j:slf4j-api:1.7.6"
    implementation "ch.qos.logback:logback-classic:1.2.3"
    implementation "ch.qos.logback:logback-core:1.2.3"

to

    implementation "org.slf4j:slf4j-api:2.0.5"
    implementation "ch.qos.logback:logback-classic:1.4.5"
    implementation "ch.qos.logback:logback-core:1.4.5"

However, when doing this update we get the following error :

java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

We are using spring-boot, but have excluded it's logging packages which worked on the previous versions of the logging packages seen above. This is done via :

configurations {
    all*.exclude module: 'spring-boot-starter-logging'
}

We believe to be using the correct updated dependencies for these new versions shown. We are unsure what is causing the issue as we followed other recommendations without any luck. If anyone can help, it be greatly appreciated.

Thank you

Upvotes: 6

Views: 12169

Answers (2)

MikanMu
MikanMu

Reputation: 61

Actually the reason is that logback-classic remove org/slf4j/impl/StaticLoggerBinder from v1.3.0, and spring-boot 2.x only support for logback to v1.2.x(currently is 1.2.12).

Here is the related issues: https://github.com/spring-projects/spring-boot/issues/34708 https://github.com/spring-projects/spring-boot/issues/12649

Upvotes: 4

zawarudo
zawarudo

Reputation: 2496

StaticLoggerBinder is not present in version org.slf4j-2.0.5. From what I see you can find that dependency for StaticLoggerBinder here

group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.19.0'

https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl

I also checked and the StaticLoggerBinder is present even in the latest version which is 2.19.0

Also, I checked the old version you had of slf4j-api 1.7.6. https://mvnrepository.com/artifact/org.slf4j/slf4j-api/1.7.6

That dependency also does not have StaticLoggerBinder either, but it is present in the dependency of log4j-slf4j-impl which I provided above.

Upvotes: 2

Related Questions