Execution failed for task ':compileKotlin' (gradle)

Hi.
Im trying to compile my project through the command line. It compiles successfully in intellij, but not in command line.
Whenever I run: “gradle build” and “gradlew build”
I get this error:

> Task :compileKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileKotlin'.
> Failed to query the value of task ':compileKotlin' property 'compilerRunner$kotlin_gradle_plugin'.
   > Kotlin could not find the required JDK tools in the Java installation. Make sure Kotlin compilation is running on a JDK, not JRE.

My program versions:
image

Here is my build.gradle.kts file

plugins {
    kotlin("jvm") version "1.6.10"
    kotlin("plugin.serialization") version "1.6.10"
    id("org.jlleitschuh.gradle.ktlint") version "10.2.1"
}

repositories {
    mavenCentral()
}

dependencies {
    implementation(group = "org.http4k", name = "http4k-core", version = "4.20.2.0")
    implementation(group = "org.http4k", name = "http4k-server-jetty", version = "4.20.2.0")
    implementation(group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version = "1.3.2")
    implementation(group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version = "0.3.2")
    implementation(group = "org.slf4j", name = "slf4j-api", version = "2.0.0-alpha5")
    runtimeOnly(group = "org.slf4j", name = "slf4j-simple", version = "2.0.0-alpha5")
    implementation(group = "org.postgresql", name = "postgresql", version = "42.+")
    implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.2")
    testImplementation(kotlin("test"))
}

tasks.register<Copy>("copyRuntimeDependencies") {
    into("build/libs")
    from(configurations.runtimeClasspath)
}

It runs the “gradle clean” and “gradlew clean” successfully. I tried deleting the .gradle folder an doing it all over again, etc. Nothing… im trying to solve this for hours. Can the wonderful and amazing kotlin community help me? Thanks!

You probably use JRE instead of JDK for compillation. Please ensure, you use JDK.

Thanks you. My JAVA_HOME was pointing to JRE, but it should point to a JDK.

1 Like