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
}
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'.
> 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'.
6 Replies
JavaBot
JavaBot•5d ago
⌛ This post has been reserved for your question.
Hey @elegos! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st•5d ago
You should have this option in your setting
No description
dan1st
dan1st•5d ago
Java › Import: Gradle: Java: Home Set this to your Java installation directory
elegos
elegosOP•5d ago
Should I point to java.exe or to the JDK folder? Oh, it's the java home, so the JDK folder (in theory) It works flawlessly! Thank you very much!
JavaBot
JavaBot•5d ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot•5d ago
Post Closed
This post has been closed by <@366713959396409346>.
Want results from more Discord servers?
Add your server