javakotlingradleintellij-idea

How to solve "Failed to calculate the value of task ':compileJava' property 'javaCompiler'" when building the default "hello world"gradle project


I'm new to kotlin,gradle,java and idea. I'm running IDEA 2023.2.5 on Windows 10. The java version is shown below

C:\Users\Administrator>java -version
java version "17.0.10" 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 17.0.10+11-LTS-240)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.10+11-LTS-240, mixed mode, sharing)

The gradle project I created is the default "Hello world" project. However, when I try to build it, the error msgs are shown below:

Failed to calculate the value of task ':compileJava' property 'javaCompiler'.
Unable to download toolchain matching the requirements ({languageVersion=8, vendor=any, implementation=vendor-specific}) from 'https://api.foojay.io/disco/v3.0/ids/99916d5878e922e25b4f443774d694e6/redirect'.
Could not HEAD 'https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u402-b06/OpenJDK8U-jdk_x64_windows_hotspot_8u402b06.zip'.
Connect to github.com:443 [github.com/20.205.243.166] failed: Connection timed out: no further information
Connection timed out: no further information

The first two links in the msgs are available when I try to download the zip file in manual.

But github.com/20.205.243.166 is not available and shows "Not Found"

I also checked the build.gradle.kts whose contents are shown below:

plugins {
    kotlin("jvm") version "1.9.22"
    application
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

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

tasks.test {
    useJUnitPlatform()
}

kotlin {
    jvmToolchain(8)
}

application {
    mainClass.set("MainKt")
}

I tried to change jvmToolchain(8) to jvmToolchain(11) but the problem is just the same. So what should I check or change now?


Solution

  • Thanks to Till Kuhn whose comment:

    If your JVM Major Version is 17, you should probably also use jvmToolchain(17) instead of 11. Also take a look at this IntelliJ Support Issue, it may give you additional pointers since the resulting error message in this issue looks similar. Good luck!

    provided the answer - it worked when I used jvmToolchain(17).