SLF4J: Class path contains multiple SLF4J bindings

Maven 2Slf4j

Maven 2 Problem Overview


I'm getting the following error. It seems there are multiple logging frameworks bound to slf4j. Not sure how to resolve this. Any help is greatly appreciated.

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/admin/.m2/repository/org/slf4j/slf4j-log4j12/1.6.4/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/admin/.m2/repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

Maven 2 Solutions


Solution 1 - Maven 2

Resolved by adding the following exclusion in the dependencies (of pom.xml) that caused conflict.

<exclusions>
    <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </exclusion>
</exclusions> 

Solution 2 - Maven 2

Gradle version;

configurations.all {
    exclude module: 'slf4j-log4j12'
}

Solution 3 - Maven 2

The error probably gives more information like this (although your jar names could be different)

> SLF4J: Found binding in > [jar:file:/D:/Java/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class] > SLF4J: Found binding in > [jar:file:/D:/Java/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.8.2/log4j-slf4j-impl-2.8.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]

Noticed that the conflict comes from two jars, named logback-classic-1.2.3 and log4j-slf4j-impl-2.8.2.jar.

Run mvn dependency:tree in this project pom.xml parent folder, giving:

dependency tree conflict

Now choose the one you want to ignore (could consume a delicate endeavor I need more help on this)

I decided not to use the one imported from spring-boot-starter-data-jpa (the top dependency) through spring-boot-starter and through spring-boot-starter-logging, pom becomes:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

in above pom spring-boot-starter-data-jpa would use the spring-boot-starter configured in the same file, which excludes logging (it contains logback)

Solution 4 - Maven 2

Sbt version:

Append exclude("org.slf4j", "slf4j-log4j12") to the dependency that transitively includes slf4j-log4j12. For example, when using Spark with Log4j 2.6:

libraryDependencies ++= Seq(
  // One SLF4J implementation (log4j-slf4j-impl) is here:
  "org.apache.logging.log4j" % "log4j-api" % "2.6.1",
  "org.apache.logging.log4j" % "log4j-core" % "2.6.1",
  "org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.6.1",
  // The other implementation (slf4j-log4j12) would be transitively
  // included by Spark. Prevent that with exclude().
  "org.apache.spark" %% "spark-core" % "1.5.1" exclude("org.slf4j", "slf4j-log4j12")
)

Solution 5 - Maven 2

1.Finding the conflicting jar

If it's not possible to identify the dependency from the warning, then you can use the following command to identify the conflicting jar

mvn dependency: tree

This will display the dependency tree for the project and dependencies who have pulled in another binding with the slf4j-log4j12 JAR.

  1. Resolution

Now that we know the offending dependency, all that we need to do is exclude the slf4j-log4j12 JAR from that dependency.

Ex - if spring-security dependency has also pulled in another binding with the slf4j-log4j12 JAR, Then we need to exclude the slf4j-log4j12 JAR from the spring-security dependency.

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
           <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
    </dependency>

Note - In some cases multiple dependencies have pulled in binding with the slf4j-log4j12 JAR and you don't need to add exclude for each and every dependency that has pulled in. You just have to do that add exclude dependency with the dependency which has been placed at first.

Ex -

<dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

</dependencies>

Solution 6 - Maven 2

I just ignored/removed that jar file.

enter image description here

Solution 7 - Maven 2

<!--<dependency>-->
     <!--<groupId>org.springframework.boot</groupId>-->
     <!--<artifactId>spring-boot-starter-log4j2</artifactId>-->
<!--</dependency>-->

I solved by delete this:spring-boot-starter-log4j2

Solution 8 - Maven 2

Just use only required dependency, not all :))). For me, for normal work of logging process you need this dependency exclude others from pom.xml

<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-api</artifactId>
		<version>1.7.5</version>
	</dependency>

	<dependency>
		<groupId>ch.qos.logback</groupId>
		<artifactId>logback-classic</artifactId>
		<version>1.1.8</version>
	</dependency>

	<dependency>
		<groupId>ch.qos.logback</groupId>
		<artifactId>logback-core</artifactId>
		<version>1.1.8</version>
	</dependency>

Solution 9 - Maven 2

This is issue because of StaticLoggerBinder.class class belongs to two different jars. this class references from logback-classic-1.2.3.jar and same class also referenced from log4j-slf4j-impl-2.10.0.jar. both of jar in classpath. Hence there is conflict between them. This is reason of log file is not generation even though log4j2.xml file in classpath [src/main/resource].

We have so select one of jar, I recommend use log4j-slf4j-impl-2.10.0.jar file and exclude logback-classic-1.2.3.jar file. Solution: open pom file and view the dependency Hierarchy [eclipse] or run
mvn dependency:tree command to find out the dependency tree and source of dependency that download the dependency. find the conflicting dependency and exclude them. For Springboot application try this.

<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
			<exclusions>
					<exclusion>
						<groupId>org.springframework.boot</groupId>
						<artifactId>spring-boot-starter-logging</artifactId>
					</exclusion>
				</exclusions>
		</dependency>
	<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-logging</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

This is working fine for me after struggling a lots.

Solution 10 - Maven 2

... org.codehaus.mojo cobertura-maven-plugin 2.7 test ch.qos.logback logback-classic tools com.sun ...

I fixed with this

... org.codehaus.mojo cobertura-maven-plugin 2.7 test ch.qos.logback logback-classic tools com.sun ...

Solution 11 - Maven 2

For me, it turned out to be an Eclipse/Maven issue after switch from log4j to logback. Take a look into your .classpath file and search for the string "log4j".

In my case I had the following there:

<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.7.1/slf4j-log4j12-1.7.1.jar"/>
<classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.17/log4j-1.2.17.jar" />

Removing those entries from the file (or you could regenerate it) fixed the issue.

Solution 12 - Maven 2

For me the answer was to force a Maven rebuild. In Eclipse:

  1. Right click on project-> Maven -> Disable Maven nature
  2. Right click on project-> Spring Tools > Update Maven Dependencies
  3. Right click on project-> Configure > Convert Maven Project

Solution 13 - Maven 2

I solved this by going to Project Structure from my Intellij project. I deleted the file named: Maven: org.apache.logging.log4j:log4j-to-slf4j-impl:2.14.1 enter image description here

This file is not shown in this picture. You may see two libraries mentioned as log4j-to-slf4j. Delete one and you are good to go.

Solution 14 - Maven 2

I had the same problem. In my pom.xml i had both

 <dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-simple</artifactId>
		<version>1.7.28</version>
	</dependency>

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-web</artifactId>
		<version>2.2.1.RELEASE</version>
	</dependency>

When i deleted the spring-boot-starter-web dependency, problem was solved.

Solution 15 - Maven 2

I got this issue in a non-maven project, two depended jar each contained a slf4j. I solved by remove one depended jar, compile the project(which of course getting failure) then add the removed one back.

Solution 16 - Maven 2

In case these logs are the result of this fix: https://stackoverflow.com/a/9919375/2894819

When one of your libraries actually use it. And your application doesn't need SL4J just replace implementation to runtimeOnly.

// contains dependency to sl4j-api
implementation("com.github.doyaaaaaken:kotlin-csv-jvm:1.2.0")

// add this to remove both warnings
runtimeOnly("org.slf4j:slf4j-nop:1.7.36")

In that case when you run your app the actual dependency will be included once by the library and won't be included to the bundle of your application.jar itself.

Solution 17 - Maven 2

In my case I had 2 sources of dependencies for log4 one in C:\Program Files\smcf.ear directory and the second from maven which caused the multiple binding for sl4j.

Deleting the smcf.ear directory solved the issue for me.

Solution 18 - Maven 2

The combination of <scope>provided</scope> and <exclusions> didn't work for me.

I had to use this:

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <scope>system</scope>
    <systemPath>${project.basedir}/empty.jar</systemPath>
</dependency>

Where empty.jar is a jar file with literally nothing in it.

Solution 19 - Maven 2

Seems removing .m2 directory and :

mvn install -DskipTests -T 4 resolved this issue for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1493140View Question on Stackoverflow
Solution 1 - Maven 2user1493140View Answer on Stackoverflow
Solution 2 - Maven 2KeremView Answer on Stackoverflow
Solution 3 - Maven 2TiinaView Answer on Stackoverflow
Solution 4 - Maven 2RuudView Answer on Stackoverflow
Solution 5 - Maven 2NafazBenzemaView Answer on Stackoverflow
Solution 6 - Maven 2nobodyView Answer on Stackoverflow
Solution 7 - Maven 2GankView Answer on Stackoverflow
Solution 8 - Maven 2MusaView Answer on Stackoverflow
Solution 9 - Maven 2Rajeev RathorView Answer on Stackoverflow
Solution 10 - Maven 2pradeep charan jadiView Answer on Stackoverflow
Solution 11 - Maven 2helmyView Answer on Stackoverflow
Solution 12 - Maven 2DS.View Answer on Stackoverflow
Solution 13 - Maven 2Raihanul Alam HridoyView Answer on Stackoverflow
Solution 14 - Maven 2Anna GaitanidiView Answer on Stackoverflow
Solution 15 - Maven 2Alan AckartView Answer on Stackoverflow
Solution 16 - Maven 2AnoDestView Answer on Stackoverflow
Solution 17 - Maven 2Shay RiberaView Answer on Stackoverflow
Solution 18 - Maven 2Alex RView Answer on Stackoverflow
Solution 19 - Maven 2bhavin brahmkshatriyaView Answer on Stackoverflow