问题
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]
回答1:
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. :-(
回答2:
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 (e.g. sudo apt install maven), then activate it in Eclipse.
P.S: After you've installed Maven on your system, the command mvn dependency:tree
will also work.
回答3:
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.
回答4:
In case there is any question as the the cause, run maven from the command line for the project (i.e. mvn clean package). You will not see the error. As Christoph Andriessens said, it's in the IDE.
来源:https://stackoverflow.com/questions/63518376/eclipse-maven-slf4j-class-path-contains-multiple-slf4j-bindings