vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

Can not build gradle project with jdk 17

Open NamekMaster opened this issue 6 months ago • 4 comments

My project requires jdk 17 to build. I use jenv to manage jdk and I set it to use java 17 locally but it seems the extension always use 21 to build project. I can build the project successfully in the terminal. I think the extension should use the java configured in java_home to build the project. java home:

echo $JDK_HOME
/Users/user/.jenv/versions/17

Error log:

[info] [gradle-server] Gradle Server started, listening on 52563
[info] Gradle client connected to server
[info] Java Home: /Users/user/.cursor/extensions/redhat.java-1.43.1-darwin-arm64/jre/21.0.7-macosx-aarch64
[info] JVM Args: --add-opens=java.base/java.util=ALL-UNNAMED,--add-opens=java.base/java.lang=ALL-UNNAMED,--add-opens=java.base/java.lang.invoke=ALL-UNNAMED,--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED,--add-opens=java.base/java.nio.charset=ALL-UNNAMED,--add-opens=java.base/java.net=ALL-UNNAMED,--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED,-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=UTF-8,-Duser.country=CN,-Duser.language=en,-Duser.variant
[info] Gradle User Home: /Users/user/.gradle
[info] Gradle Version: 7.6.4
[error] FAILURE: Build failed with an exception.

I tried to add the config below but still not working

  "java.configuration.runtimes": [
    {
      "name": "JavaSE-17",
      "path": "/Users/user/.jenv/versions/17",
      "default": true
    }
  ],
  "gradle.java.home": "/Users/user/.jenv/versions/17"

NamekMaster avatar Jul 18 '25 09:07 NamekMaster

Assuming you're using gradle to build your project, how are you telling gradle that your project needs Java 17 to compile and not whatever is available? Btw: doesn't gradle use JAVA_HOME, not JDK_HOME? Have you tried setting java.import.gradle.java.home?

tsmaeder avatar Sep 11 '25 15:09 tsmaeder

java.import.gradle.java.home is working. But I am confused why JAVA_HOME is not supported in this extension. Build the project in terminal is good with JAVA_HOME. According to official documents, gradle should use JAVA_HOME and I haven't heard about JDK_HOME. I supposed that JAVA_HOME is a more commonly used variable. On the other hand, I prefer JAVA_HOME because it leverages the benefit of jenv or other environment manager program. I think it's also not a good idea that creating more and more variables in different build tools.

NamekMaster avatar Sep 12 '25 01:09 NamekMaster

echo $JDK_HOME /Users/user/.jenv/versions/17

🤷

Btw. where did you copy the error log from? If from the "Output" view, which channel did you copy?

tsmaeder avatar Sep 12 '25 08:09 tsmaeder

@tsmaeder It seems like that there is a command called "Java: Show Build Job Status" will open in "Terminal" view. I can't reproduce this problem again now even if I remove the java.import.gradle.java.home. When you start the project, a notification will show on the left bottom as shown below, you can also click the "check details" to see the logs. Image

NamekMaster avatar Sep 16 '25 02:09 NamekMaster