Gradle: setTestClassesDir(File) method has been deprecated

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.

Trouble shooting

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.

The solution

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.

Acknowledgements

I would like to thank Malin Ekholm for finding my typos.

Resources



(less...)

Pages

About
Events
Why

Categories

Agile
Automation
BDD
Clean code
Continuous delivery
Continuous deployment
Continuous integration
Cucumber
Culture
Design
DevOps
Executable specification
Git
Gradle
Guice
J2EE
JUnit
Java
Javascript
Kubernetes
Linux
Load testing
Maven
Mockito
New developers
Pair programming
PicoContainer
Presentation
Programming
Public speaking
Quality
React
Recruiting
Requirements
Scala
Selenium
Software craftsmanship
Software development
Spring
TDD
Teaching
Technical debt
Test automation
Tools
Web
Windows
eXtreme Programming

Authors

Thomas Sundberg
Adrian Bolboaca

Archives

Meta

rss RSS