1
votes

I am getting compile error. I am not sure which dependency provides this error. I am using @slf4j lombok annotation to implement logging in my classes.

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/home/andrius/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.25/110cefe2df103412849d72ef7a67e4e91e4266b4/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/home/andrius/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]

I am not quite sure in which module and what should I exclude to avoid this.

My setup of Gradle dependencies below.

dependencies {
implementation('org.springframework.boot:spring-boot-starter') {
    exclude group: 'ch.qos.logback'
}
compileOnly('org.projectlombok:lombok:1.18.2')
testCompileOnly('org.projectlombok:lombok:1.18.2')
annotationProcessor('org.projectlombok:lombok:1.18.2')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('net.sf.dozer:dozer:5.4.0')
compile('org.springframework.boot:spring-boot-starter-logging')
compile('io.springfox:springfox-swagger2:2.9.2')
compile('io.springfox:springfox-swagger-ui:2.9.2')
testImplementation('org.springframework.boot:spring-boot-starter-test') {
    exclude(module: 'spring-boot-starter-logging')
 }
}
1
Did you ever figure out which library (besides spring-boot-starter) was pulling in logback?Mathew Alden

1 Answers

1
votes

There are a few things to check:

I have found that gradle can be sticky with its cache, so when I get persistent problems like this, I like to rm -rf ~/.gradle/caches - obviously be careful here and don't wipe out more than you intend.

Run gradle dependencies to find out where your logging implementations are coming from. You'll generally find that there'll be a library somewhere that's pulling in slf4j-log4j12 and another that's pulling in logback-classic. You appear to have excluded the ch.qos.logback group from where its being pulled in by the spring-boot-starter, so I'm guessing that you want that implementation excluded. Therefore, you want to find out where else ch.qos.logback is being pulled in and exclude it there as well.

Its a laborious process, and I feel that Spring is being a bit over opinionated by choosing logback-classic, but that's the way it is for the moment.

Not quite an answer, but I hope this helps.