springspring-bootspring-logback

LoggerFactory Exception in Spring boot version 3.1.2


I am getting following exception on bootRun task:

Exception in thread "main" java. lang.IllegalArgumentException:
LoggerFactory is not a Logback LoggerContext but Logback is on classpath.
Either remove logback or the competing implementation
( class org.slf4j.helpers.NOPLoggerFactory loaded from 
file:home/user/.gradle/caches/modules-x/files-x.1/{org}/repo/snapshot/{random_number}/repo.jar.

**Using**
logback-classic version 1.4.8

Solution

  • The error message is quite clear. Logback and SLF4J's NOPLoggerFactory are both present on the classpath and this is causing a conflict between these two logging implementations. NOPLoggerFactory might have been added as a transitive dependency by some other library you are using. To exclude it, write this in your build.gradle:

    configurations {
        all {
            exclude group: 'org.slf4j', module: 'slf4j-nop'
        }
    }
    

    Also, clear the gradle cache:

    gradle clean build --refresh-dependencies