Got "Unknown Kotlin JVM target: 20" when running "gradle build"

Hi team,

I got an issue when running gradle build. The error messages show that:

* What went wrong:
Execution failed for task ':buildSrc:compileKotlin'.
> Error while evaluating property 'compilerOptions.jvmTarget' of task ':buildSrc:compileKotlin'.
   > Failed to calculate the value of property 'jvmTarget'.
      > Unknown Kotlin JVM target: 20

Does anyone know how to resolve it?

Don’t run Gradle with a Java version it is not compatible with: Compatibility Matrix

Thanks Vampire! I switch the java version to an earlier one and the issue was resolved.

1 Like

I’m having the same problem with a problem but with version 21. I noticed in the Compatibility Matrix that this version is not compatible with Gradle, although I have another project created with spring boot initializer and it’s running. Could not find the difference between those projects that made the spring boot project work and the project created with Graldew init not work.

Any thought?

As you provide no information at all about your builds, it is nearly impossible to guess.
Yes, builds can work with 21 or can fail with 21.
That is is not yet offiicially supported does not mean that it cannot work in some cases already.
If you have really the exact same error like OP, I guess your failing project does have buildSrc while the working one does not.

1 Like

Thank you very much for the reply @Vampire!

I was not sure what could help but here’s some information about those projects:

  1. I have uploaded both on git, and by doing that noticed that they have different languages (not working was created for Kotlin), but then I created the third one with Kotlin using the spring initializer and it worked as well.

https://github.com/jgabrielmiranda/firstgradleproject - with error (Kotlin language)
https://github.com/jgabrielmiranda/kotlinproject - no error (Kotlin language)
https://github.com/jgabrielmiranda/restfull - no error (Java language)

  1. By Typing .\gradlew --version I have those informations

Gradle 8.4

Build time: 2023-10-04 20:52:13 UTC
Revision: e9251e572c9bd1d01e503a0dfdf43aedaeecdc3f

Kotlin: 1.9.10
Groovy: 3.0.17
Ant: Apache Ant™ version 1.10.13 compiled on January 4 2023
JVM: 21.0.1 (Oracle Corporation 21.0.1+12-29)
OS: Windows 11 10.0 amd64

  1. My javac --version is javac 20.0.2

  2. and java -version is
    java version “1.8.0_391”
    Java™ SE Runtime Environment (build 1.8.0_391-b13)
    Java HotSpot™ 64-Bit Server VM (build 25.391-b13, mixed mode)

I’ve started studying those technologies recently but as I’ve searched, looks like both have buildSrc. And I’ve been running gradle commands always with “.\gradlew”.

I’m really glad you replied to my question. Tks again @Vampire !

Giving wrong information is even worse than giving no information.
You said “looks like both have buildSrc”, but none of your three linked projects have buildSrc.
And thus your error is also not the same as OP for whom it failed at building buildSrc.
For you it fails at running :app:compileKotlin as - unlike in the other two projects - you configured a JVM toolchain of 21.
So this has nothing to do with the Java version you run Gradle with.
You explicitly configure to use Java 21 for compiling Kotlin code in app, no matter which Java version is used to run Gradle itself.
Using JVM toolchains feature is a good idea, but not if you use a Java version that your Kotlin version is not compatible with.
Kotlin 1.9.20 is the first version that supports Java 21 but you use 1.9.10.

1 Like

Oh Sorry about giving the wrong information. As said, I’m, new to those technologies, just made a quick search on buildSrc on the internet and thought it was just files generated in the project.

It was all just generated by the Gralde init, so I was unaware of those configurations. But I was intrigued by why was not running on the project generated by gradle init.

After changing Kotlin version to 1.9.20 the build worked as you said this version is supported.

Have no word on how to thank you. And sorry if this is not the actual place to be asking those questions.

Hope to get enough knowledge to help others one day :slight_smile:

Again, thank you very much!!!

2 Likes