multiple SLF4J bindings with m2e in Eclipse 2020-06

Viewed 3414

Got a problem getting slf4j working for me with m2e. This is not the first time to state this problem. However, others have a more specific case and still no answer.

I installed Eclipse-jee fresh. For test I created a simplest maven project from maven-archetype-quickstart. It simply prints out Hello World!

Although applying m2e it compiles and runs fine, I get the messages in red

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/rschumacher/install/eclipse-jee/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:/C:/Users/rschumacher/install/eclipse-jee/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 happens with any maven project when performing run as/Maven test.
It doesn't help to look at the dependency:tree of the pom.xml, as the conflicting bindings are with m2e and osgi (as far as I can interprete the messages).

As result, slf4j ignores the configuration and is no longer usable from within Eclipse with m2e installed.
If I start mvn test from a commandline, no such messages appear. slf4j logging is working as it should.

Do you got any idea or workaround in order to have slf4j working again with m2e?

3 Answers

With the help of Nickel Cao's answer, I was (eventually) able to fix the SLF4J error/warning messages you are describing. However, Nickel's solution only fixed the default Maven Run As goals. My custom Maven build goals - the only goals I ever use - also had to be updated before the SLF4J errors went away.

NOTE: I fixed the problem in Eclipse 2020-09, not 2020-06.

Here's how I did it, with some screenshots. (Sorry, I don't have the reputation to embed them.)

  1. Add your external Maven installation directory in Window -> Preferences -> Maven -> Installations: Screenshot of Maven Installations dialog (I'm pretty sure the checkbox is how you select the default Maven runtime..)
  2. Open the Run Configurations dialog by clicking Run As -> Run Configurations from the Project's context menu: Screenshot of Project's Run As context menu
  3. Update each of your custom Maven build configurations to use the external Maven Runtime: Screenshot of Run Configurations dialog

Once I had performed this last step, my custom Run-As Maven builds stopped generating the SLF4J errors: Screenshot of victory

Cheers!

Latest Update:

Pls see JMR's answer for More comprehensive solution


You should go to Window -> preference -> Maven -> Installations

Then instead of using EMBEDDED m2e, add an external one, which you has installed manually, then choose it and apply.

eclipse preference screenshot

This how I resolve this problem. So according to same mechanism, you may resolve this problem also by delete maven in system path.

The issue you have should be fixed for the EMBEDDED Maven runtime since Eclipse m2e 1.18.2. Eclipse m2e 1.19.0, which also includes the fix, is part of the Eclipse 2021-12 release.

If you are interested, this is the PullRequest in the m2e GitHub repository that fixed the issue: https://github.com/eclipse-m2e/m2e-core/pull/369

Related