I have a scala based project built with gradle, it contains java and scala code. We are upgrading to OpenJDK11 from oracle jdk 8. We are upgrading with binaries compatible with JDK8 by adding release flag to compiler. I achieved that for java files by
if(JavaVersion.current() > JavaVersion.VERSION_1_9) {
subprojects {
tasks.withType(JavaCompile) {
options.compilerArgs += ["--release", "8"]
}
tasks.withType(ScalaCompile) {
options.compilerArgs += ["--release", "8"]
}
}
}
in build.gradle. This works fine ie the build seems to add the release flag, to test this I added a JDK 11 specific change to java class. ie Used String.repeat in java class and compiler throws error but if I add the same to a scala class it compiles without reporting the error that repeat() is not an method available. What am I missing does adding release flag to scala compilation mean nothing or how can I achieve this? The intention is to have binaries that run on JDK 8 or JDK11 we are ok for now to compromise on using JDK11 based new features. So I need to make sure no other developers add jdk11 specific code so that we end up on runtime issues.