Removed errant jar from compile, still present in integTest

A while ago I ran into (and thought I resolved) an issue where my code needed Commons-IO version 2.4, but Gradle was putting Commons-IO 1.4 early on the classpath, giving me errors. I implemented a fix for that, and it seemed to resolve the problem. I’m now seeing today that an integration test is failing with a similar error, and after parsing through the “–debug” output, I see that it correctly removed commons-io-1.4.jar from the compile classpath, but the integration test is still running with that in the classpath.

Here’s an excerpt from my “build.gradle” that shows my integration test setup, and the solution I implemented to remove commons-io-1.4 from the classpath:

    sourceSets {
    main {
        compileClasspath = configurations.compile.minus files("$gradle.gradleHomeDir/lib/commons-io-1.4.jar")
}
    integTest {
        groovy.srcDir file("src/integTest/groovy")
        resources.srcDir file("src/integTest/resources")
        runtimeClasspath = output + compileClasspath
    }
}

dependencies {
    integTestCompile sourceSets.main.output
    integTestCompile configurations.testCompile
    integTestCompile sourceSets.test.output
    integTestRuntime configurations.testRuntime

    testCompile( 'com.netflix.nebula:nebula-test:2.2.1' ) {
        exclude module: 'groovy-all'
    }
}

task integTest(type: Test) {
    testClassesDir    = sourceSets.integTest.output.classesDir
    classpath         = sourceSets.integTest.runtimeClasspath
    // This forces integration tests to always run if the task is run.
    outputs.upToDateWhen { false }
}

What do I have to do to get the same thing to happen when I run my integration tests?

Update:

I thought perhaps that simply copying that “compileClasspath” assignment in the “main” sourceset into the “integTest” sourceset, but that failed miserably. I copied it to the line before the “runtimeClasspath” assignment, but that caused weird compile errors.

Update2:

Ok, I might have a solution, but this is acquiring a smell. I ended up with the following sourceset declaration:

sourceSets {
main {
    compileClasspath = configurations.compile.minus files("$gradle.gradleHomeDir/lib/commons-io-1.4.jar")
}
 integTest {
    groovy.srcDir file("src/integTest/groovy")
    resources.srcDir file("src/integTest/resources")
    runtimeClasspath = output + compileClasspath - files("$gradle.gradleHomeDir/lib/commons-io-1.4.jar")
}

}

It’s bad enough to reference that “$gradle.gradleHomeDir” thing, but now I have to do it twice. I suppose I can define an ext variable for it. That will be a small improvement.