Inconsistent compile behavior with gradle running on jvm 8 vs 11

We have a gradle build script that includes a custom code generation task that requires running the JavaCompile task on java 8, while all other compile tasks should use java 11. We have this configured like so:

tasks.withType(JavaCompile).configureEach {task ->
    if ( task.name === 'generatePolyglotApis' ) {
        javaCompiler = javaToolchains.compilerFor {
            languageVersion = JavaLanguageVersion.of(8)
        }
    } else {
        javaCompiler = javaToolchains.compilerFor {
            languageVersion = JavaLanguageVersion.of(11)
        }
    }
}

We also have this code at the top of the script:

println ''
println '>>>'
println "Gradle version: ${project.getGradle().gradleVersion}"
println "Java version: ${Jvm.current()}"
println '>>>'
println ''

This build script runs on lots of different machines, and we have a convention on each machine to define JAVA#_HOME environment variables, and we edit the gradle wrapper scripts to use these custom environment variables instead of vanilla JAVA_HOME, and each machine points these env variables to the install dirs for whatever jvm versions they’ve got.

When we have the wrapper scripts set to use JAVA8_HOME, we see this output at the top of the build:

>>>
Gradle version: 7.2
Java version: 1.8.0_91 (Oracle Corporation 25.91-b14)
>>>

…and all the compilation steps run to completion without error, including generatePolyglotApis and the tasks that require java 11.

When we change the gradle wrapper scripts to instead use JAVA11_HOME, we get this when the build script runs:

>>>
Gradle version: 7.2
Java version: 11.0.12 (Eclipse Foundation 11.0.12+7)
>>>

…but now the build fails due to a TaskExecutionException for the java 8 generatePolyglotApis task, caused by a stack overflow:

Caused by: java.lang.RuntimeException: java.lang.StackOverflowError
        at com.sun.tools.javac.main.Main.compile(Main.java:553)
        at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
        at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
        at org.gradle.internal.compiler.java.IncrementalCompileTask.call(IncrementalCompileTask.java:89)
        at org.gradle.api.internal.tasks.compile.AnnotationProcessingCompileTask.call(AnnotationProcessingCompileTask.java:94)
        at org.gradle.api.internal.tasks.compile.ResourceCleaningCompilationTask.call(ResourceCleaningCompilationTask.java:57)
        at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:54)

Does anybody have thoughts on what could be going wrong here? We are currently running fine with the gradle wrapper scripts wired to launch gradle on java 8, but are confused why launching on java 11 would cause this failure.

any suggestions here? even if just to figure out more context about why this error is occurring?

I found the cause of this problem, which had to do with an over-long javadoc parameter description, though I don’t know why it exhibits under java 11 but not 8.

I don’t believe it had anything to do with gradle.