Move to OpenJDK-11 but compile in Java 8

you need to set the sourceCompatibility too.

See this post here Gradle, "sourceCompatibility" vs "targetCompatibility"?


As of Java 9 you can use the --release N option to cross-compile with Gradle. Setting the sourceCompatibility and targetCompatibility is not enough because in that case you need to set the bootClasspath to JDK N too. See What is the --release flag in the Java 9 compiler? for more details.

Instead, use the Java 9+ "--release" compilerArg like this:

compilerArgs.addAll(['--release', '8'])

https://docs.gradle.org/current/dsl/org.gradle.api.tasks.compile.CompileOptions.html


I'd say :

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

Because the default value of sourceCompatibility is the version of the current JVM in use.

source : https://docs.gradle.org/current/userguide/java_plugin.html