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

How can I set the Java runtime version to JDK 8 for a specific project? #1555

Open
JLP04 opened this issue Jul 31, 2020 · 8 comments
Open

How can I set the Java runtime version to JDK 8 for a specific project? #1555

JLP04 opened this issue Jul 31, 2020 · 8 comments

Comments

@JLP04
Copy link

JLP04 commented Jul 31, 2020

[provide a description of the issue]

Environment
  • Operating System: macOS Catalina 10.15.6
  • JDK version: 14.0.2 but I want to run my program with 1.8.0_221
  • Visual Studio Code version: 1.47.3
  • Java extension version: 0.65.0
Steps To Reproduce
  1. [step 1]
  2. [step 2]

[Please attach a sample project reproducing the error]
Please attach logs

Current Result
Expected Result
Additional Informations

I was wondering if there was a way to make a single project run java programs using JDK 8. I have already put this specific JDK in java.configuration.runtimes but I am not seeing the status bar icon to change the Java Language Level. I have gotten it to work by setting default to true for the JDK I want to use in java.configuraiton.runtimes but I was wondering if there was a way to do this that didn't involve changing my settings for all projects.

@testforstephen
Copy link
Collaborator

I guess you're not using any build tool. For the standalone Java files, the extension will use the language level from the default JDK runtime you configured in user setting.

If you use maven or gradle, their build file such as pom.xml/build.gradle provides options to specify the complier version.

@JLP04
Copy link
Author

JLP04 commented Aug 3, 2020

So if I don't use a build tool I have to change the runtime in settings?

@testforstephen
Copy link
Collaborator

yes, you can only change the global user setting for that.

@JLP04
Copy link
Author

JLP04 commented Aug 5, 2020

Thanks

@n-peugnet
Copy link

Would it be possible to make the java.configuration.runtimes setting overridable on a per workspace basis ? It would indeed be useful for a "no build tool" setup.
Right now I don't really understand how it can be useful to register multiple runtimes in the User settings if only the default one can be used.

@fbricon
Copy link
Collaborator

fbricon commented Oct 20, 2020

@n-peugnet what sorts of projects are you using with vscode-java?

@n-peugnet
Copy link

n-peugnet commented Oct 21, 2020

@fbricon I would say any kind of project. For bigger projects and especially if I need to work with other people I usually setup Maven to have a common build system. But for smaller/school project I would love to be able to just make a folder and set all the build configuration in my .vscode/settings.json, or maybe even better, using a dedicated config file in .vscode containing the java project configuration as vscode-cpptools is doing for example. This also applies to #1615 and to the source folders as well as for now it seems that it is only configurable by right-click -> Add folder to Java source path (I haven't already looked if there is an issue for this).

For the current issue, I think that it would be sufficient to have a java.project.runtime in .vscode/settings.json which allows to select one of the runtimes defined in the User settings based on its name property.

@n-peugnet
Copy link

n-peugnet commented Oct 21, 2020

And to clarify my current use case, I am currently doing school projects using Hadoop. The latest stable version 3.2.1 does not support Java11 so I have to use an older version (1.8). I am using vscode to code and compile some MapReduce jobs but these have to be compiled with 1.8 for yarn to be able to run them. I use Java11 in almost every other projects so I would like not to have to switch the default version in my User settings each time I switch projects. Maven would be overkill and since I am already setting the referencedLibraries in vscode to get autocompletion, it is very easy to just use the class compiled by vscode-java to run the jobs.

Another solution would be to be able to set the -target option of javac to compile 1.8 compliant classes (or maybe add a compilerOptions setting allowing a broader range of configuration) but as the runtime configuration already exists I thought that it would be easier to implement.

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

No branches or pull requests

4 participants