SLF4J: Class path contains multiple SLF4J bindings error using selenium-server

1.3k Views Asked by At

How to resolve the error Class path contains multiple SLF4J bindings while using selenium-server-4.0.0-alpha-5.jar and gerrit-acceptance-framework-3.1.4.jar

Error stack trace:

[RemoteTestNG] detected TestNG version 7.2.0
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/DELL/Desktop/selenium/selenium-server-4.0.0-alpha-5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/DELL/.m2/repository/com/google/gerrit/gerrit-acceptance-framework/3.1.4/gerrit-acceptance-framework-3.1.4.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.JDK14LoggerFactory]
Starting ChromeDriver 80.0.3987.106 (f68069574609230cf9b635cd784cfb1bf81bb53a-refs/branch-heads/3987@{#882}) on port 24218
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Starting ChromeDriver 80.0.3987.106 (f68069574609230cf9b635cd784cfb1bf81bb53a-refs/branch-heads/3987@{#882}) on port 48737
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Starting ChromeDriver 80.0.3987.106 (f68069574609230cf9b635cd784cfb1bf81bb53a-refs/branch-heads/3987@{#882}) on port 5045
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.

===============================================
Suite
Total tests run: 3, Passes: 0, Failures: 3, Skips: 0
===============================================
1

There are 1 best solutions below

0
On

This error message...

Class path contains multiple SLF4J bindings.

...implies that there are more than one SLF4J bindings present on the class path.


Multiple bindings were found on the class path

As per the documentation:

SLF4J API is designed to bind with one and only one underlying logging framework at a time. If more than one binding is present on the class path, SLF4J will emit a warning, listing the location of those bindings.

From the error stacktrace it is pretty evident that StaticLoggerBinder.class seems to be available in both the following class paths:

  • Within C:/Users/DELL/Desktop/selenium/selenium-server-4.0.0-alpha-5.jar!/org/slf4j/impl
  • Within C:/Users/DELL/.m2/repository/com/google/gerrit/gerrit-acceptance-framework/3.1.4/gerrit-acceptance-framework-3.1.4.jar!/org/slf4j/impl

Solution

When multiple bindings are available on the class path, select one and only one binding you wish to use, and remove the other bindings. The list of locations that SLF4J provides in this warning usually provides sufficient information to identify the dependency transitively pulling in an unwanted SLF4J binding into your project. So in your project's pom.xml file you have to exclude one of the SLF4J binding when declaring the unscrupulous dependency. As an example, to exclude StaticLoggerBinder.class from selenium-server-4.0.0-alpha-5.jar:

</dependencies>
  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.X</version>

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

As an alternative you can also exclude the StaticLoggerBinder.class from gerrit-acceptance-framework-3.1.4.jar

Note: The warning emitted by SLF4J is just that, a warning. 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. As of version 1.6.6, SLF4J will name the framework/implementation class it is actually bound to.