Current Gradle Version Lacks Support for Java 21

I wanted to explore and test Project Loom and the virtual threads it offers in newer versions of Java, such as version 20 and 21. I also wanted to see how they work in Spring alongside Kotlin and compare the syntax between them and Coroutines. I found that the latest version of Gradle does not yet support Java version 21. So, be cautious because IntelliJ and Spring Initializr give you the option to select Java 21, but in the build.gradle.kts file, you’ll still see that Kotlin will be compiled into version 17. It’s a bit of a workaround, but Gradle supports version 20 in Gradle 8.1 and 8.3.

Gradle compability matrix: https://docs.gradle.org/current/userguide/compatibility.html

You need to setup in IntelliJ idea – Project settings – Project 

And replace this task in build.gradle


tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs += "-Xjsr305=strict"
jvmTarget = "20"
}
}

For more information, you can check here: https://github.com/Kotlin-server-squad/kss-spring-webflux/blob/main/build.gradle.kts

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *

×