Filed under: Gradle, — Tags: Deprecation — Thomas Sundberg — 2017-08-14
When upgrading from Gradle 3 to Gradle 4, I got a deprecation warning in my build. The message looked like this:
Gradle now uses separate output directories for each JVM language, but this build assumes a single directory for all classes from a source set. This behaviour has been deprecated and is scheduled to be removed in Gradle 5.0
at build_6ku42cnecj8o3fcbd4eugmgr$_run_closure3.doCall(/Users/tsu/projects/tsu/thinkcode.se/build.gradle:37)
The setTestClassesDir(File) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the setTestClassesDirs(FileCollection) method instead.
at build_6ku42cnecj8o3fcbd4eugmgr$_run_closure3.doCall(/Users/tsu/projects/tsu/thinkcode.se/build.gradle:37)
My question was "What? How do I upgrade my build to get rid of the warning?". I searched but neither Google nor Gradle had a migration plan ready for me.
The code Gradle was complaining about looked like this:
task acceptanceTest(type: Test) {
description = 'Runs the acceptance tests'
group = 'verification'
testClassesDir = sourceSets.acceptanceTest.output.classesDir
classpath = sourceSets.acceptanceTest.runtimeClasspath
}
The line Gradle complains about is this: testClassesDir = sourceSets.acceptanceTest.output.classesDir
where I define where the compiled tests should be found.
This test task runs my acceptance tests that are defined in a separate source set. This allows me to define a separate set of acceptance tests. My acceptance tests are slow so I don't want them mixed with my unit tests.
The source set I use for the separation looks like this:
sourceSets {
acceptanceTest {
java.srcDir file('src/acceptanceTest/java')
resources.srcDir file('src/acceptanceTest/resources')
compileClasspath += main.output + test.output + configurations.testRuntime
runtimeClasspath += output + compileClasspath
}
}
The deprecation warning wants me to refer to all of the output directories for the test classes. In this case I only have one.
My solution is to update how I refer to the output directory. I updated the test task like this:
task acceptanceTest(type: Test) {
description = 'Runs the acceptance tests'
group = 'verification'
testClassesDirs = sourceSets.acceptanceTest.output
classpath = sourceSets.acceptanceTest.runtimeClasspath
}
The offending line has been updated to testClassesDirs = sourceSets.acceptanceTest.output and the
deprecation warning is gone.
I would like to thank Malin Ekholm for finding my typos.