Build environment (classpath, env) changes when overriding a groovy plugin task


(Chris Stephens) #1

I started getting some mysterious failures in my test task when I upgraded to a newer version of the spring & neo4j frameworks. Basically the spring context was unable to initialize the beans, but was failing deep in the java stack with ‘java.lang.VerifyError: Uninitialized object exists on backward branch 60’. I struggled to figure out what the problem was since I was able to run the tests through intellij without an issue.

Finally I found that if I overwrote the test task within my build file the context would somehow magically get corrected and the test suite ran without a problem. Is there any way I can figure out what is the difference between the default task’s environment and the environment that is getting passed when I have overridden the task locally?

exerpt of build.gradle:

project(':graph-web') {
    apply plugin: 'war'
    apply plugin: 'tomcat'
    configurations {
        wsDocAnnotationProcessor
    }
      war {
        archiveName = 'product-graph.war'
    }
      // Why does adding this work?
    task test(type: Test, dependsOn: testClasses, overwrite: true) {
    }
      sourceSets.main.resources.srcDir "src/main/webapp"
      dependencies {
        compile project(':graph-business')
          compile "org.springframework:spring-web:$springVersion"
        compile "org.springframework:spring-webmvc:$springVersion"
        compile "org.springframework:spring-aspects:${springVersion}"
        compile 'javax.servlet:javax.servlet-api:3.0.1'
        compile 'com.backcountry:jsondoc-springmvc:1.0.2-SNAPSHOT'
        compile 'org.hibernate:hibernate-validator:4.2.0.Final'
        runtime "com.fasterxml.jackson.core:jackson-core:2.1.0"
        runtime "com.fasterxml.jackson.core:jackson-databind:2.1.0"
        testCompile "com.jayway.jsonpath:json-path:0.8.1"
        testCompile 'com.google.code.gson:gson:2.2.4'
        testCompile "org.neo4j:neo4j-kernel:$neo4jVersion:tests"
          wsDocAnnotationProcessor 'org.versly:versly-wsdoc:1.0-SNAPSHOT'
        def tomcatVersion = '7.0.35'
        tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}"
        tomcat "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
        tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
            exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
        }
      }

(Peter Niederwieser) #2

The overwritten ‘Test’ task may not be executing any tests since no configuration information is provided. Can you double-check this?

PS: Overwriting tasks has some known issues and should generally be avoided. It shouldn’t ever be necessary to overwrite a task with a task of the same type.


(Chris Stephens) #3

I also would have expected that no tests would be run if I overrode the task but I have verified that the test suite is actually running (~50% of my tests were broken post upgrade due to breaking changes).

I’m sure there is a better way to explicitly declare the dependencies and also would prefer not to override the tasks. Plus I pity any person after me you is reading that code and trying to understand what I did =)

For reference, in order to get the ‘build’ task to work in addition to the ‘test’ task I had to add the following:

task check(type: Test, dependsOn: testClasses, overwrite: true) {
    }
    task test(type: Test, dependsOn: testClasses, overwrite: true) {
    }

(Chris Stephens) #4

Is there an easy way to print out the working environment so I could compare the diffs during execution? Or any other way to dump the build environment? I tried iterating through the classpath printing out all of the entries but ended up with an exception:

task test2(type: Test, dependsOn: testClasses) {
        classpath.each { println it }
}
A problem occurred evaluating root project 'graph-base'.
> Could not resolve all dependencies for configuration ':graph-web:testRuntime'.
   > Could not find org.slf4j:slf4j-api:1.7.2.
     Required by:
         graph-base:graph-web:0.1-SNAPSHOT