Java Community | Help. Code. Learn.JC|HCL
Java Community | Help. Code. Learn.โ€ข16mo agoโ€ข
10 replies
elegos

VSCode and RedHat Java: wrong JDK for gradle tasks

Dear community,

I've installed OpenJDK 21. I have configured JAVA_HOME and JDK_HOME accordingly, setup the JDK Runtime under Project Settings (JavaSE-21, which correctly points to the Eclipse Adoptium's jdk 21 folder). The
build.gradle
file is configured to run with Java version 21 (see following config). I have no clue why, when I start the Gradle tasks via the Gradle integration tab, it uses the java.exe included in the redhat's extension (java v. 17).

Running gradlew from the shell, it works correctly (i.e.
.\gradlew.bat init
)

Thanks for any help ๐Ÿ™‚

plugins {
    id 'fabric-loom' version '1.8-SNAPSHOT'
    id 'maven-publish'
}

#   ...

tasks.withType(JavaCompile).configureEach {
    it.options.release = 21
}

java {
    // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
    // if it is present.
    // If you remove this line, sources will not be generated.
    withSourcesJar()

    sourceCompatibility = JavaVersion.VERSION_21
    targetCompatibility = JavaVersion.VERSION_21
}


Gradle's output:
> Configure project :
Fabric Loom: 1.8.12
<-------------> 0% WAITING
> IDLE
> IDLE
> IDLE
> IDLE

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'my-project-name'.
> Failed to setup Minecraft, java.lang.IllegalStateException: Minecraft 1.21.3 requires Java 21 but Gradle is using 17

* Try:
> Run with --stacktrace option to get the stack trace.
Could not execute build using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-8.10.2-bin.zip'.
Was this page helpful?