JDK21 with sourceCompatibility = 20

492 views Asked by At

I'm working on a gradle spring-boot hybrid project (Kava + Kotlin). Due compatibility reasons there is not yet a version for Kotlin 21. Would it be recommended to use JDK21 with target 20? Since JDK17 and JDK21 are LTS, in this case does it make any difference which version of the language I will use within it?

I would like to know if it is recommended to use version 20 with JDK21, or if it would be better to use version 17 and wait for the release of 21.

1

There are 1 answers

0
dan1st might be happy again On

As far as I understood Gradle's compatibility matrix, you should be able to compile Java 21 applications with Gradle already but using you need a different JVM for running Gradle. You should be able to do this by configuring your PATH with Java 20 (or 17) and setting your JAVA_HOME to a Java 21-JDK.

In general, if you want to use features from Java 19 or 20, you shouldn't use a source compatibility of 20. However, there aren't many features that were finalized in these releases.

Since many vendors (including the Oracle build of OpenJDK and the free version of OracleJDK) stopped supporting Java 20, you might rather want to use Java 17 as your source compatibility level instead of 20.