Maurizio Sellitti
Maurizio Sellitti

Reputation: 73

Gradle intelliJ plugin SLF4J: Class path contains multiple SLF4J bindings

I'm developing a plugin for intelliJ IDEA and I'm using an external library. When I run, I have this problem.

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/molos/Desktop/Thesis-folder/Thesis-project/build/idea-sandbox/plugins/Thesis-project/lib/slf4j-log4j12-1.6.0.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/molos/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2019.3.1/52292e4f8a0ccb3ceb08bd81fd57b88923ac8e99/ideaIC-2019.3.1/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

This is my build.gradle.

plugins {
id 'java'
id 'maven-publish'
id 'org.jetbrains.intellij' version '0.4.10'
}

version '1.0-SNAPSHOT'

apply plugin: 'maven'

sourceCompatibility = 1.8

repositories {
   mavenCentral()
   maven {
      url = 'https://repo.maven.apache.org/maven2'
}


dependencies {
  // https://mvnrepository.com/artifact/com.github.mauricioaniche/ck
compile group: 'com.github.mauricioaniche', name: 'ck', version: '0.4.4'
// https://mvnrepository.com/artifact/org.eclipse.jgit/org.eclipse.jgit
compile group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '2.2.0.201212191850-r'
// https://mvnrepository.com/artifact/org.apache.commons/commons-csv
compile group: 'org.apache.commons', name: 'commons-csv', version: '1.1'



}

// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version '2019.3.1'
}

I tried the many solutions that I found around, but I could not solve.

Can someone help me?

Upvotes: 3

Views: 2049

Answers (2)

Ryu S.
Ryu S.

Reputation: 1989

I was able to remedy this problem by excluding the slf4j-api dependency inside my build.gradle.kts file.

dependencies {
    detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.17.1")

    // JGIT
     implementation(group="org.eclipse.jgit", name="org.eclipse.jgit", version="5.11.1.202105131744-r"){
           exclude(group="org.slf4j", module="slf4j-api")
     }

}

Upvotes: 2

Atorian
Atorian

Reputation: 817

I had the same problem in a recent app with Gradle 6.7 and Spring Boot 2.3.4.RELEASE. I ended up excluding what the IntelliJ plugin was pulling in, and a few other things.

plugins {
    id 'java'
    id 'org.jetbrains.intellij' version '0.5.1'
    id 'org.springframework.boot' version '2.3.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}
...
configurations {
    // the ideaIC module is adding the slf4j-log4j12 module and StaticLoggerBinder.class
    implementation.exclude(group: 'com.jetbrains', module: 'ideaIC')
    
    // the groovy plugin was adding groovy to the runtime
    implementation.exclude(group: 'org.codehaus.groovy', module: 'groovy-all')

    // spring-boot-logging brought in logback and log4j-to-slf4j which I don't want
    //   since I am using org.springframework.boot:spring-boot-starter-log4j2
    compile.exclude(group: 'ch.qos.logback')
    compile.exclude(group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j')
}

Its kind of brute-force, but it works. Maybe there is some setting missing in the Gradle file that results in these unnecessary modules being added. I certainly don't expect these plugins to add such things to my JAR.

Upvotes: 0

Related Questions