Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

integrationTestCompile gradle dependency ignored

Following a few blog posts I tried to create a separate source folder for integration testing in gradle. I wanted also to add some additinal (arquillian) dependencies to my integrationTest task, but the integrationTestCompile seems to be ignored and I get a compilation error with the additional dependecy not resolved. When I change the dependecy to testCompile it works fine. Why is that so and how to change it? My simple test class:

//compilation fails with  [Static type checking] - The variable [ArquillianSputnik] is undeclared
@TypeChecked
@RunWith(ArquillianSputnik)
class TestSpec extends Specification {


}

and gradle.build:

apply plugin: 'groovy'
apply plugin: 'war'

war.dependsOn 'native2ascii'

task native2ascii << {

    ant.delete() {
        fileset(dir: "${processResources.destinationDir}") {
            include(name: '*.properties')
        }
    }
    ant.native2ascii(src: 'src/main/resources/',
            dest: "${processResources.destinationDir}",
            includes: '**/*.properties',
            encoding: 'UTF-8')
}

repositories {
    mavenCentral()
    maven {
        url 'http://repository.jboss.org/nexus/content/groups/public'
    }
    mavenLocal()
}

sourceSets.main.java.srcDirs = []
sourceSets.main.groovy.srcDirs += ["src/main/java"]

sourceSets {
    integrationTest {
        groovy.srcDir file('src/integration-test/groovy')
        resources.srcDir file('src/integration-test/resources')
        compileClasspath = sourceSets.main.output + configurations.testCompile
        runtimeClasspath = output + compileClasspath + configurations.testRuntime
    }
}

dependencies {
    //(...) non-test dependencies cut out for clarity

    testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
    testCompile 'cglib:cglib-nodep:2.2.2'
    testCompile 'org.objenesis:objenesis:1.2'

    //when integrationTestCompile is changed to testCompile the compilation works and the test is executed
    integrationTestCompile 'org.jboss.arquillian.spock:arquillian-spock-container:1.0.0.Beta3'
    integrationTestCompile 'org.jboss.arquillian.graphene:graphene-webdriver:2.0.3.Final'
    integrationTestCompile 'org.jboss.as:jboss-as-arquillian-container-managed:7.2.0.Final'
}

task integrationTest(type: Test, dependsOn: 'test') {
    testClassesDir = sourceSets.integrationTest.output.classesDir
    classpath = sourceSets.integrationTest.runtimeClasspath

}

check.dependsOn 'integrationTest'
like image 997
Kamil Roman Avatar asked Mar 24 '26 01:03

Kamil Roman


1 Answers

First, you want to add to the compile and runtime classpaths rather than replace them. This really just means using the += operator rather than the = one. Additionally, you really only want to add the other sourcesets output, we'll deal with configurations separately.

compileClasspath += sourcesets.main.output + sourcesets.test.output
runtimeClasspath += sourcesets.main.output + sourcesets.test.output

Next, we'll want to configure our integration test configurations. Usually, this just means making them extend the test and compile ones so that they contain all those dependencies as well.

configurations {
    integrationTestCompile.extendsFrom testCompile
    integrationTestRuntime.extendsFrom testRuntime
}
like image 71
Mark Vieira Avatar answered Mar 26 '26 21:03

Mark Vieira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!