# Gradle Kotlin Build: JVM Compatibility Issue with Java 23 and Kotlin 2.0.20

**URL:** <https://discuss.kotlinlang.org/t/gradle-kotlin-build-jvm-compatibility-issue-with-java-23-and-kotlin-2-0-20/29556>\
**Category:** Native\
**Created:** [November 25, 2024, 4:32pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-build-jvm-compatibility-issue-with-java-23-and-kotlin-2-0-20/29556 "2024-11-25T16:32:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![europa](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/europa/32/8080_2.png) [@europa](https://discuss.kotlinlang.org/u/europa)\
**Post date:** [November 25, 2024, 4:32pm UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-build-jvm-compatibility-issue-with-java-23-and-kotlin-2-0-20/29556/1 "2024-11-25T16:32:51Z")

</div>

Hi Everyone,

I’m facing a compatibility issue in my project involving Gradle, Kotlin, and Java 23. Here’s the problem:

### **Problem Description**

Error:

```auto
Execution failed for task ':compileKotlin'.
> Inconsistent JVM-target compatibility detected for tasks 'compileJava' (23) and 'compileKotlin' (22).

```

- I am using:
  - **Java version** : `23.0.1`
  - **Gradle version** : `8.8`
  - **Kotlin Gradle Plugin version** : `2.0.20`

- My `build.gradle.kts` is configured to align the Java toolchain to JVM 23 while Kotlin targets a supported version (JVM 20).

### **My `build.gradle.kts` File**

```auto
plugins {
    kotlin("jvm") version "2.0.20"
}

group = "com.test"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(kotlin("test"))
}

tasks.test {
    useJUnitPlatform()
}

```

**./gradlew --version**

```auto

------------------------------------------------------------
Gradle 8.10.2
------------------------------------------------------------

Build time: 2024-09-23 21:28:39 UTC
Revision: 415adb9e06a516c44b391edff552fd42139443f7

Kotlin: 1.9.24
Groovy: 3.0.22
Ant: Apache Ant(TM) version 1.10.14 compiled on August 16 2023
Launcher JVM: 23.0.1 (Oracle Corporation 23.0.1+11-39)
Daemon JVM: C:\Program Files\Java\jdk-23 (no JDK specified, using current Java home)
OS: Windows 11 10.0 amd64

```

### **My `Main.kt` File**

```auto
package com.cdcadvania

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
fun main() {
    val name = "Kotlin"
    //TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
    // to see how IntelliJ IDEA suggests fixing it.
    println("Hello, " + name + "!")

    for (i in 1..5) {
        //TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
        // for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
        println("i = $i")
    }
}

```

---

<div class="post-metadata">

**Author:** ![brunojcm](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/brunojcm/32/5116_2.png) [@brunojcm](https://discuss.kotlinlang.org/u/brunojcm)\
**Post date:** [December 2, 2024, 4:39am UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-build-jvm-compatibility-issue-with-java-23-and-kotlin-2-0-20/29556/2 "2024-12-02T04:39:10Z")

</div>

Have you tried adding this in the root of your `build.gradle.kts`?

```auto
kotlin {
    jvmToolchain(21) // you can try other versions here
}

```

---

<div class="post-metadata">

**Author:** ![sqvaard](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/sqvaard/32/10250_2.png) [@sqvaard](https://discuss.kotlinlang.org/u/sqvaard)\
**Post date:** [December 29, 2024, 10:21am UTC](https://discuss.kotlinlang.org/t/gradle-kotlin-build-jvm-compatibility-issue-with-java-23-and-kotlin-2-0-20/29556/4 "2024-12-29T10:21:01Z")

</div>

If you want to use JVM 23, you need to use Kotlin 2.1.0 or higher. If you want to keep using Kotlin 2.0.x for some reason, you need to use JVM 22 or earlier.

See [Which versions of Kotlin are compatible with which versions of Java? - Stack Overflow](https://stackoverflow.com/questions/63989767/which-versions-of-kotlin-are-compatible-with-which-versions-of-java) for more details.
