From 92a0b0a00c0aabd434dcbe8e3f7c40b9edb7981a Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 9 May 2018 06:17:43 -0400 Subject: [PATCH] Stop forking groovyc (#30471) This is a follow-up to our previous change to only fork javac if needed to respect the Java compiler home (via JAVA_HOME). This commit makes the same change for groovyc: we only fork groovyc if the JDK for Gradle is not the JDK specified for the compiler (via JAVA_HOME). --- .../org/elasticsearch/gradle/BuildPlugin.groovy | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index 88ded22fb4d..9cc5bb82552 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -535,10 +535,15 @@ class BuildPlugin implements Plugin { } // also apply release flag to groovy, which is used in build-tools project.tasks.withType(GroovyCompile) { - final JavaVersion targetCompatibilityVersion = JavaVersion.toVersion(it.targetCompatibility) - options.fork = true - options.forkOptions.javaHome = new File(project.compilerJavaHome) - options.compilerArgs << '--release' << targetCompatibilityVersion.majorVersion + 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 = compilerJavaHomeFile + options.compilerArgs << '--release' << JavaVersion.toVersion(it.targetCompatibility).majorVersion + } } } }