Inconsistent JVM-target compatibility detected for tasks 'compileJava' (23) and 'compileKotlin' (20)

I have installed IntelliJ and I created a new Kotling project with Gradle:

  • Type: Kotlin
  • Build System: Gradle
  • JDK: 23 Oracle OpenJDK 23.0.1
  • Gradle DLS: Kotlin
  • Gradle distribution: Wrapper
  • Gradle version: 8.10.2

When i start my Kotlin application I get this error:

Inconsistent JVM-target compatibility detected for tasks 'compileJava' (23) and 'compileKotlin' (22).

This is my Main.kt:

package com.s

//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")
    }
}

build.gradle.kts

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

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

repositories {
    mavenCentral()
}

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

tasks.test {
    useJUnitPlatform()
}

gradle.properties


kotlin.code.style=official

settings.gradle.kts


rootProject.name = "fortra-count"

What is wrong? How do I fix this?

I also faced the same issue recently and I fixed it by changing the kotlin jvm version to 2.1.0 in build.gradle.kts