Run parallel test task using gradle

Java-Seekar picture Java-Seekar · May 22, 2014 · Viewed 33.8k times · Source

We use JUnit as a test framework. We have many projects. We use gradle (version 1.12) as a build tool. To run the unit tests in parallel using gradle we use the below script in every project under test task.

maxParallelForks = Runtime.runtime.availableProcessors()

Ex:

test {    
  maxParallelForks = Runtime.runtime.availableProcessors()       
}

We also maintain the single gradle.properties file.

Is it possible to define test.maxParallelForks = Runtime.runtime.availableProcessors() in gradle.properties file rather than defining it in each build.gradle file under test task?

Answer

Peter Niederwieser picture Peter Niederwieser · May 22, 2014

$rootDir/build.gradle:

subprojects {
    tasks.withType(Test) {
        maxParallelForks = Runtime.runtime.availableProcessors()
    }
}