I'm getting this error:
LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.jul.JDK14LoggerFactory loaded from file:/C:/Users/casi2/.gradle/caches/modules-2/files-2.1/org.mock-server/mockserver-junit-jupiter-no-dependencies/5.15.0/40fd1649b4faff31363e100994bcb0ece8ead3cc/mockserver-junit-jupiter-no-dependencies-5.15.0.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.jul.JDK14LoggerFactory java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.jul.JDK14LoggerFactory loaded from file:/C:/Users/casi2/.gradle/caches/modules-2/files-2.1/org.mock-server/mockserver-junit-jupiter-no-dependencies/5.15.0/40fd1649b4faff31363e100994bcb0ece8ead3cc/mockserver-junit-jupiter-no-dependencies-5.15.0.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.jul.JDK14LoggerFactory
In this gradle.build
file,I tried to remove the org.slf4j
dependency from my test:
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation ('org.mock-server:mockserver-junit-jupiter-no-dependencies:5.15.0') {
exclude group: 'org.slf4j'
}
But has no effect. Most posts I found are for old gradle versions. What I'm missing here?
You should move the exclude from the junit dependency to the spring-boot dependency, as that is the one that is transitively bringing in slf4j.
testImplementation('org.springframework.boot:spring-boot-starter-test:3.2.1') {
exclude group: 'org.slf4j'
}
testImplementation('org.mock-server:mockserver-junit-jupiter-no-dependencies:5.15.0')
(took the liberty of adding a version number to the spring-boot dependency to make it work for me)
You can find out where a dependency is coming from using the dependencyInsight task. In this case, I used ./gradlew dependencyInsight --configuration testRuntimeClasspath --dependency org.slf4j:slf4j
and it told me that the spring-boot dependency was the one adding slf4j.