Skip to content
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

Option to set/change the Project SDK from Detected SDKs #3857

Closed
mamilic opened this issue Nov 14, 2024 · 3 comments
Closed

Option to set/change the Project SDK from Detected SDKs #3857

mamilic opened this issue Nov 14, 2024 · 3 comments
Labels

Comments

@mamilic
Copy link

mamilic commented Nov 14, 2024

Would it be possible to allow users to set or modify the "Project Java SDK" in VS Code? Currently, it seems to be auto-detected. This proposed setting would allow users to select from a dropdown of detected SDKs, with an option to include manually configured SDKs.

Scope and Application:
The configured SDK setting would be applied across all relevant Java-related components within VS Code, such as:

  • JDT Language Server (JDTLS)
  • VS Code Gradle Extension
  • Any other Java-related extensions, where applicable

This setting would primarily impact runtime configurations. For example:

  • The Gradle daemon version used for project builds()as sometime the version can not be detected from gradle scripts, as it is dynamic)
  • The Java version leveraged by JDTLS for code navigation and browsing (e.g., when exploring standard classes like String)
  • Maven and other project dependencies as relevant
    Important Note:
    This setting should not alter the Java version used by the JDTLS server itself.

Thank you for considering this feature. It would provide users with more flexibility in managing their development environment and streamline project compatibility across different Java SDK versions.

@rgrunber
Copy link
Member

rgrunber commented Nov 14, 2024

The auto detection is done by https://github.com/Eskibear/node-jdk-utils#readme . The setting java.configuration.runtimes should allow you to manually configure JDKs though. See https://github.com/redhat-developer/vscode-java/wiki/JDK-Requirements#project-jdks . The way it works with Gradle (or even Maven) is that the build files (build.gradle, pom.xml) would assert a specific source/target/release version of the JDK (eg. 11) and vscode-java will look for a configured JDK that suports that (eg. JavaSE-11). If none can be found, it looks like our auto detection tries to configure an existing JDK to the environment (eg. source/target = 19 -> JavaSE-19 -> /path/to/some/detected/jdk-23/). If you have https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack , this actually has a UI menu, "Project Settings" that allows you to configure these compiler options.

Image

There is code in the language server to help users when the Gradle version is not compatible with a chosen JDK, https://github.com/eclipse-jdtls/eclipse.jdt.ls/blob/ba8d0910917bab70b8565af15d7960c2e1ae8058/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/GradleUtils.java#L83-L120 .

Let me know if there's anything about this that doesn't work as you expect.

@mamilic
Copy link
Author

mamilic commented Nov 14, 2024

@rgrunber , thanks a lot! Did not know that configuration already exist. This issue can be closed.

@rgrunber
Copy link
Member

We should do a better job at advertising the various options : https://github.com/redhat-developer/vscode-java?tab=readme-ov-file#supported-vs-code-settings . There's quite a lot there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants