I have a spring-boot starter webapplication. Recently I have been getting errors related to Logback being on the classpath. Below is my current gradle file:
buildscript {
ext {
springBootVersion = '1.3.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE')
classpath 'net.saliman:gradle-cobertura-plugin:2.3.0'
}
}
apply plugin: 'groovy'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
configurations {
all*.exclude module: 'spring-boot-starter-logging'
}
dependencies {
compile 'com.github.groovy-wslite:groovy-wslite:1.1.2'
compile('org.springframework.boot:spring-boot-starter-web')
compile("org.springframework.boot:spring-boot-starter-data-rest")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile('org.springframework.boot:spring-boot-starter-log4j')
compile('org.codehaus.groovy:groovy')
compile("org.apache.accumulo:accumulo-core:1.6.2") {
exclude module: "slf4j-log4j12"
}
compile("com.h2database:h2")
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile 'com.github.groovy-wslite:groovy-wslite:1.1.2'
testCompile 'org.codehaus.groovy:groovy-json:2.4.5'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
testCompile 'org.spockframework:spock-spring:1.0-groovy-2.4'
testCompile 'cglib:cglib-nodep:3.1'
}
tasks.withType(Test) {
systemProperty 'spring.profiles.active', 'test'
}
With this configuration, I can run the war or use bootRun to start the application. However, my spring integration tests all fail with the error
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation
I have looked over the internet, specifically at these stack overflow questions for a solution. The questions and answers on those questions helped me be able to run the application by excluding Logback. However the tests are still failing. This article, in particular helped me ensure that logback was not in the dependency tree. When I run
gradlew -q dependencies --configuration compile
and view the output, logback is nowhere to be found in the dependency tree anymore with the above build.gradle file. However, running Spring integration tests like the one below fails with the error message pasted above:
@SpringApplicationConfiguration(classes = Application.class, initializers = ConfigFileApplicationContextInitializer.class)
@WebIntegrationTest
class CanaryIntegrationSpec extends Specification {
@Value('${local.server.port}') int port
def "when we call single test endpoint then we get a response back"() {
when:
ResponseEntity entity = new RestTemplate().getForEntity("http://localhost:$port/query/test", String.class)
then:
entity.statusCode == HttpStatus.OK
entity.body == /{"hello":"world"}/
}
}
TL;DR: My configuration works for running the war, but all integration tests now fail. How can I fix my configuration so that tests pass again?