-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect JDK used when running with Gradle #3633
Comments
hello. I created an example test project and checked its operation... If you want to use the coursework project with JDK 18, you can do it as follows. {
"java.configuration.runtimes": [
{
"name": "JavaSE-18", // 💡Install Java 18 on the system and add the path
"path": "/home/username/.jdks/openjdk-18",
},
{
"name": "JavaSE-19",
"path": "/home/username/.jdks/openjdk-19",
},
{
"name": "JavaSE-20", // 💡Renamed to JavaSE-20.
"path": "/home/username/.jdks/openjdk-20",
},
{
"name": "JavaSE-22", // 💡Renamed to JavaSE-22.
"path": "/home/username/.jdks/openjdk-22",
"default": true
},
],
// 💡 Path to Java Home to run Gradle for Java
"java.jdt.ls.java.home": "/home/username/.jdks/openjdk-19"
} TODO:
Example TestExample ProjectThis is a simple example program that prints the currently running Java Home. System environmentIn my case, to prevent gradle from automatically downloading a JDK that cannot be used, I disabled automatic downloading and manually specified the JDK path. %USERPROFILE%/.gradle/gradle.propertiesorg.gradle.java.installations.auto-detect=false
org.gradle.java.installations.auto-download=false
org.gradle.java.installations.paths=C:/JDK/8,C:/JDK/11,C:/JDK/17,C:/JDK/18,C:/JDK/21 VSCode - User Settings.json "java.configuration.runtimes": [
{
"name": "JavaSE-17",
"path": "C:\\JDK\\17\\",
"default": true
},
{
"name": "JavaSE-21",
"path": "C:\\JDK\\21\\"
},
{
"name": "JavaSE-11",
"path": "C:\\JDK\\11\\"
},
{
"name": "JavaSE-18",
"path": "C:\\JDK\\18\\"
},
{
"name": "JavaSE-1.8",
"path": "C:\\JDK\\8\\"
}
],
// Java runtime path to run Gradle for Java
// Required after installing "Gradle for Java". If the JAVA_HOME environment variable is set globally on the system, it does not need to be set.
"java.import.gradle.java.home": "C:\\JDK\\21", Java Version settings for example project - build.gradle// Apply a specific Java toolchain to ease working on different environments.
java {
toolchain {
languageVersion = JavaLanguageVersion.of(18)
}
} Run it by clicking the Run link that appears above the main() method.If you run the test project with the settings as above...
Run it by clicking application > run Task in “Gradle for Java”
|
@mklinkj Wow, I really appreciate the detailed solution. And apologies for the typo. Thanks to your example, I've managed to find the source of the problem. There appeared to be two separate problems, which affected the "Language Support for Java" and "Gradle for Java" extensions separately. I do have the following setting in my java {
toolchain {
languageVersion = JavaLanguageVersion.of(18)
}
} Here are the two problems (not bugs but user errors) I found:
I found that setting Gradle properties additions I used:
Other notes: Thanks again for your help! |
I did this because I didn't want Gradle to automatically download and use JDKs that weren't on my system and preferred to use JDKs that I had manually installed on my system. Glad it worked out for you and thanks for the answer. Have a nice day 👍 There are parts where I gave speculative answers. 😅 // Specifies the folder path to the JDK (17 or more recent) used to launch the Java Language Server.
// This setting will replace the Java extension's embedded JRE to start the Java Language Server.
"java.jdt.ls.java.home": "C:\\JDK\\17",
// The location to the JVM used to run the Gradle daemon.
"java.import.gradle.java.home": "C:\\JDK\\17",
|
Glad you were able to resolve this. Closing for now but feel free to re-open if there's some other problems. Note, as of 1.23.0 (we're about to release 1.31.0 soon), JDK detection is done automatically which should lessen the strain of users needing to populate |
Edit: Solved. Not a bug but configuration error (solution below).
Upon clicking run, I notice that my project is being run with the JDK located under
~/.gradle/jdks
instead of the JDK I specified insettings.json
.Environment
Steps To Reproduce
Unable to attach sample files as it is for coursework.
Current Result
This is what it runs the project with:
Expected Result
This is what it should run the project with:
Additional Informations
settings.json
file:java.jdt.ls.java.home
is being used by the "Gradle for Java" extension by Microsoft to specify the JDK.The text was updated successfully, but these errors were encountered: