Tests aren't executed when setting the test runtimeClasspath

(Guy Brand) #1


if we define the runtimeClasspath of our tests like in the following snippet gradle doens’t execute the tests but it also doesn’t show them as UP-TO-DATE.

sourceSets {
  test {
    runtimeClasspath = files(output.resourcesDir) + files(output.classesDir) +
            sourceSets.main.output + configurations.testRuntime
:edoras-bpm-execution-core:build UP-TO-DATE
:edoras-bpm-execution-documentation:compileJava UP-TO-DATE
:edoras-bpm-execution-documentation:processResources UP-TO-DATE
:edoras-bpm-execution-documentation:classes UP-TO-DATE
:edoras-bpm-execution-documentation:jar UP-TO-DATE
:edoras-bpm-execution-documentation:zipDependencies UP-TO-DATE
:edoras-bpm-execution-documentation:filterResources UP-TO-DATE
:edoras-bpm-execution-load:compileJava UP-TO-DATE
:edoras-bpm-execution-load:processResources UP-TO-DATE

We got this snippet from this post: http://forums.gradle.org/gradle/topics/classpath_order_of_test_resources_and_test_classes_while_executing_tests



(Szczepan Faber) #2

If you need to reorder the test classpath see the workaround below. It’s not beautiful and we’ll address it at some point. You can also try manipulating the test’s classpath via the test task properties: http://gradle.org/docs/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:classpath

sourceSets {
  test {
    def orderedOutput = files(output.resourcesDir) + files(output.classesDir)
    //we still want to refer to 'output' to let the implicit task dependencies get configured
    runtimeClasspath = orderedOutput + (output - orderedOutput) +
      sourceSets.main.output + configurations.testRuntime

Hope that helps!

(Guy Brand) #3

Thanks a lot for the quick answer. It worked.

(Peter Niederwieser) #4

If the goal is to have resources first, won’t ‘runtimeClasspath = files(output.resourcesDir) + runtimeClasspath’ do the job?

(Szczepan Faber) #5

Indeed it should work. I didn’t go that route because I’m always cautious about assigning convention mapping property with a value that is calculated from The the convention property (ie. runtimeClasspath = xxx + runtimeClasspath. However, given the file collections are lazy anyway, and the duplicates are sorted out by the composite file collection, then your solution should work fine and it is also much cleaner :slight_smile: