steve lin
steve lin

Reputation: 109

Multiple SLF4J bindings

I have two jar files in my classpath which has a dependency with slf4j. This causes a warning message in my Java program:

 SLF4J: Class path contains multiple SLF4J bindings.
 SLF4J: Found binding in  [jar:file:/usr/lib/slf4j-log4j12-1.7.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
 SLF4J: Found binding in [jar:file:/usr/lib/myprogram.jar!/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.Log4jLoggerFactory]

Is there a way to remove this warning message by only changing the gradle file, and without removing any of above jar files from my classpath?

Thanks

Upvotes: 3

Views: 13145

Answers (1)

sheltem
sheltem

Reputation: 3825

Is there a way to remove this warning message by only changing the gradle file, and without removing any of above jar files from my classpath?

No.

The only way to remove that warning is by providing only a single binding for SLF4J. And you really should do so:

Even when multiple bindings are present, SLF4J will pick one logging framework/implementation and bind with it. The way SLF4J picks a binding is determined by the JVM and for all practical purposes should be considered random.

Since you provide a binding in your own jar, the easiest way to restrict yourself to a single binding would be to exclude the slf4j-log4j12-1.7.6.jar.

Upvotes: 4

Related Questions