# While running unit test SLF4J: Class path contains multiple SLF4J bindings

**URL:** <https://discuss.gradle.org/t/while-running-unit-test-slf4j-class-path-contains-multiple-slf4j-bindings/51311>\
**Category:** Help/Discuss\
**Created:** [July 14, 2025, 11:22am UTC](https://discuss.gradle.org/t/while-running-unit-test-slf4j-class-path-contains-multiple-slf4j-bindings/51311 "2025-07-14T11:22:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![puiuvlad](https://avatars.discourse-cdn.com/v4/letter/p/90db22/32.png) [@puiuvlad](https://discuss.gradle.org/u/puiuvlad)\
**Post date:** [July 14, 2025, 11:22am UTC](https://discuss.gradle.org/t/while-running-unit-test-slf4j-class-path-contains-multiple-slf4j-bindings/51311/1 "2025-07-14T11:22:02Z")

</div>

I am trying to run a unit test and getting the following warning, and as a result I am not able to log anything during the test:

```gradle
SLF4J: Found binding in [jar:file:/C:/Users/Puiu/.gradle/caches/8.14.2/generated-gradle-jars/gradle-api-8.14.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Puiu/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.12/485f77901840cf4e8bf852f2abb9b723eb8ec29/slf4j-log4j12-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Actual binding is of type [org.gradle.internal.logging.slf4j.OutputEventListenerBackedLoggerContext]

```

It appears that there is a clash between the gradle api and my dependency.

In my dependecies I explicitly include SLF4J. I also include the gradleApi as I am using some hamcrest functionality (org.gradle.internal.impldep.org.hamcrest.BaseMatcher):

```gradle
dependencies {
...
    implementation("org.slf4j:slf4j-log4j12:1.7.12")
    testImplementation(gradleApi())
}

```

Running ‘dependencies’ produces the following output. Notice that no conflict is reported.

```gradle
testRuntimeClasspath - Runtime classpath of source set 'test'.
...
+--- org.slf4j:slf4j-log4j12:1.7.12
| +--- org.slf4j:slf4j-api:1.7.12
| \--- log4j:log4j:1.2.17
...

```

I assume that I would need to exclude the SLF4J artifact from the gradleApi dependency but the usual way of exclusion does not compile:

```gradle
    testImplementation(gradleApi()) {
        exclude(group = "org.slf4j", module = "slf4j-log4j12")
    }

```

Any suggestions?

Thanks,  
Vladimir

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [July 14, 2025, 11:35am UTC](https://discuss.gradle.org/t/while-running-unit-test-slf4j-class-path-contains-multiple-slf4j-bindings/51311/2 "2025-07-14T11:35:11Z")

</div>

The exclude and conflict do not work, as the `gradleApi()` dependency does not depend on slf4j but provides an slf4j implementation.

The question is why you depend on `slf4j-log4j12` and `gradleApi()` in your project.

Besides that you should probably not use Gradle internal classes like the one you mentioned, what do you develop? A Gradle plugin? Then you should not add an SLF4J implementation like `slf4j-log4j12` as dependency.

Only end-products like an application you write or Gradle should provide logging facade implementations like `slf4j-log4j12` to redirect the facade users to the actual logging backend provided by the end-product.

If you just want to log from your Gradle plugin you need to do it like for any other library that wants to log using SLF4J, use just `sfl4j-api`.

If you are are not developing build logic, then the `gradleApi()` dependency is highly questionable anyway.

---

<div class="post-metadata">

**Author:** ![puiuvlad](https://avatars.discourse-cdn.com/v4/letter/p/90db22/32.png) [@puiuvlad](https://discuss.gradle.org/u/puiuvlad)\
**Post date:** [July 14, 2025, 12:24pm UTC](https://discuss.gradle.org/t/while-running-unit-test-slf4j-class-path-contains-multiple-slf4j-bindings/51311/3 "2025-07-14T12:24:51Z")

</div>

Thanks Bjorn for the speedy reply.

I am developing an application and I need to log behavior (slf4j-log4j12) and need to test behavior via unit tests (hence using hamcrest).

You are right, I should use the standalone hamcrest library rather than the derivative bundled with gradle.
