unbroken-dome / gradle-testsets-plugin

A plugin for the Gradle build system that allows specifying test sets (like integration or acceptance tests).
MIT License
230 stars 50 forks source link

Updates, added to test runtimeClasspath in a sourceSet, is not visible during gradle test run #102

Closed vryzhuk closed 4 years ago

vryzhuk commented 4 years ago

Additional test runtime classpath becomes not visible during test execution when plugin test-sets applied. Test fails with NoClassDefFoundError.

How to reproduce:

  1. Create two source sets in build.gradle:

    sourceSets {
    testData {
    java {
      srcDir 'src/testData/java'
      compileClasspath += sourceSets.main.runtimeClasspath
    }
    }
    test {
    java {
      compileClasspath += sourceSets.testData.output
      runtimeClasspath += sourceSets.testData.output
    }
    }
    }
  2. Create some class in testData and create Test, which has reference to it.

  3. Run gradle build - SUCCESS

  4. Add test-sets plugin

    plugins {
    id 'org.unbroken-dome.test-sets'
    }
  5. Run gradle build - crashed during test execution phase with "> initializationError FAILED java.lang.NoClassDefFoundError: < class from testData >"

More investigations:

  1. Print test.runtimeClasspath in test.doFirst: build/classes/java/testData exist there
  2. Print files from test class in Classloader: testData classes do not exist there

Workaround: specify dependency to testData in dependencies section:

dependencies {
    testCompile sourceSets.testData.output
}
tkrullmann commented 4 years ago

Can't really reproduce this... the plugin won't do anything unless you specify test sets in the build script.