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:
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):
dependencies {
...
implementation("org.slf4j:slf4j-log4j12:1.7.12")
testImplementation(gradleApi())
}
Running ‘dependencies’ produces the following output. Notice that no conflict is reported.
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:
testImplementation(gradleApi()) {
exclude(group = "org.slf4j", module = "slf4j-log4j12")
}
Any suggestions?
Thanks,
Vladimir