Stop forking javac
We started forking javac to avoid GC overhead when running builds. Yet,
we do not seem to have this problem anymore and not forking leads to a
substantial speed improvement. This commit stops forking javac.
@@ -497,10 +497,15 @@ class BuildPlugin implements Plugin<Project> {
project.afterEvaluate {
project.tasks.withType(JavaCompile) {
final JavaVersion targetCompatibilityVersion = JavaVersion.toVersion(it.targetCompatibility)
- // we fork because compiling lots of different classes in a shared jvm can eventually trigger GC overhead limitations
+ final compilerJavaHomeFile = new File(project.compilerJavaHome)
+ // we only fork if the Gradle JDK is not the same as the compiler JDK
+ if (compilerJavaHomeFile.canonicalPath == Jvm.current().javaHome.canonicalPath) {
+ options.fork = false
+ } else {
options.fork = true
- options.forkOptions.javaHome = new File(project.compilerJavaHome)
+ options.forkOptions.javaHome = compilerJavaHomeFile
options.forkOptions.memoryMaximumSize = "512m"
+ }
if (targetCompatibilityVersion == JavaVersion.VERSION_1_8) {
// compile with compact 3 profile by default
// NOTE: this is just a compile time check: does not replace testing with a compact3 JRE
