Skip to content

Commit ad9cb45

Browse files
committed
Stop forking javac (#30462)
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.
1 parent 4dd2e91 commit ad9cb45

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

+9-4
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,15 @@ class BuildPlugin implements Plugin<Project> {
497497
project.afterEvaluate {
498498
project.tasks.withType(JavaCompile) {
499499
final JavaVersion targetCompatibilityVersion = JavaVersion.toVersion(it.targetCompatibility)
500-
// we fork because compiling lots of different classes in a shared jvm can eventually trigger GC overhead limitations
501-
options.fork = true
502-
options.forkOptions.javaHome = new File(project.compilerJavaHome)
503-
options.forkOptions.memoryMaximumSize = "512m"
500+
final compilerJavaHomeFile = new File(project.compilerJavaHome)
501+
// we only fork if the Gradle JDK is not the same as the compiler JDK
502+
if (compilerJavaHomeFile.canonicalPath == Jvm.current().javaHome.canonicalPath) {
503+
options.fork = false
504+
} else {
505+
options.fork = true
506+
options.forkOptions.javaHome = compilerJavaHomeFile
507+
options.forkOptions.memoryMaximumSize = "512m"
508+
}
504509
if (targetCompatibilityVersion == JavaVersion.VERSION_1_8) {
505510
// compile with compact 3 profile by default
506511
// NOTE: this is just a compile time check: does not replace testing with a compact3 JRE

0 commit comments

Comments
 (0)