简体   繁体   中英

Eclipse Maven: SLF4J: Class path contains multiple SLF4J bindings

I got this error when trying to run as Maven Build. Could someone please help me resolve the binding conflicts, thanks.

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Applications/Eclipse.app/Contents/Eclipse/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/Applications/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Applications/Eclipse.app/Contents/Eclipse/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/Applications/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]

This is not a bug in eclipse. We just have to uninstall the slf4j from "Maven integration for eclipse" which is an additional software already installed on the eclipse. You can see this in eclipse market place.

Do the below steps:

  1. In eclipse, Go to help -> click on Market place -> click on installed. Here you will see the Maven integration for eclipse which is already installed. 在此处输入图像描述
  2. Now click on change button. There you will see slf4j over logback is checked. Uncheck it and click on confirm button. This will uninstall the slf4j from "Maven integration for eclipse" software. 在此处输入图像描述

Now you can check that the slf4j binding error is gone when you do the maven build. Enjoy!

This is a known bug in Eclipse. A workaround is, that you install Maven separately (not using the Eclipse-embedded Maven binary).

Then you can chose that external Maven binary under: Window->Preferences->Maven->Installations

It should look like this: 在此处输入图像描述

I'm using Windows here but in Linux it's the same procedure. Install maven from your package manager (eg sudo apt install maven), then activate it in Eclipse.

PS: After you've installed Maven on your system, the command mvn dependency:tree will also work.

This seems to be a bug in Eclipse up to version 2020-09. I got this as well.

Cf. https://bugs.eclipse.org/bugs/show_bug.cgi?id=506676 .

No work around that I know of so far. Working with Maven dependencies of your project won't solve the problem since it is caused by the m2e plugin and eclipse, so it's beyond the scope of your project, it's inside the IDE. :-(

I would suggest using the Maven dependency tree plugin. Run the following from the root level of your project, where your pom.xml file sits:

mvn dependency:tree

You may do a search/grep on the output for slf4j to see which libraries are bringing in an slf4j dependency, and what version(s) are being brought in. It is also possible to further restrict the output from the command line, using GAV coordinates. However, I often find it useful to see the entire tree, if for no other reason than I can be certain that I am seeing every dependency in my project. If you can get this far, you are about halfway done.

The next step is what to do about the dependencies which are bringing in the unwanted slf4j transitive dependenc(ies). You may follow this Stack Overflow question and exclude slf4j from these dependencies, using something looking like this in your POM file:

<dependency>
    <groupId>com.example</groupId>
    <artifactId>foo-bar</artifactId>
    <version>1.2.3</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>

You may have to add multiple exclusions to remove all but the one slf4j dependency you really want to include. As a sanity check, you may run depedency tree again, to verify that you only have one implementation in your build.

In case there is any question as the the cause, run maven from the command line for the project (ie mvn clean package). You will not see the error. As Christoph Andriessens said, it's in the IDE.

This Bug is known in eclipse since 2016:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=506676

Nothing has changed for more than five years.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM