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

VSCode java home not being used #249

Closed
skypartan opened this issue Apr 1, 2020 · 9 comments
Closed

VSCode java home not being used #249

skypartan opened this issue Apr 1, 2020 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@skypartan
Copy link

Extension Name: vscode-gradle
Extension Version: 2.4.13
OS Version: Windows 1909
VSCode version: 1.43.2

Describe the bug
The extension doesn't use the java environment set in the workspace settings, instead it defaults to gradle search method, which uses the default system installation.

To Reproduce
Have a system with multiple versions of java (8 and 11 in my pc)
Configure one of them as the default (JAVA_HOME or System Path)
Configure vscode to use the other version with "java.home" setting (provided by Java extension from Red Hat)

Expected behavior
All Gradle tasks should be executed with the java version configured in the vscode "java.home" setting.

Does the bug still exist if you disable all other extensions?
Yes

@skypartan skypartan added the bug Something isn't working label Apr 1, 2020
@skypartan skypartan changed the title VSCode java.home not being used VSCode java home not being used Apr 1, 2020
@badsyntax
Copy link
Collaborator

badsyntax commented Apr 4, 2020

Hi. Thanks for the report. Yes this extension does not read any of the settings that are defined by the vscode-java extension. (Full list of settings here.)

Instead this extension uses a more standard approach of defining per-project java settings, that can be defined in gradle.properties, or via environment variables like JAVA_HOME which can be set in the project workspace settings, for example: #243 (comment) (You can also use a tool like direnv to set project specific environment vars.)

I understand the confusion the vscode-java settings can cause here. I am considering to read those settings within this extension, but I am not fully convinced it's a good idea yet.

@skypartan
Copy link
Author

Hi. Personally I think it makes sense to use vscode-java settings, mainly because it's the way to go for java development in VSCode, so you can basically assume that it is installed with this extension.

For the gradle.properties file, I don't think it is the best place for this type of configuration. The gradle's documentation says that it should be added to VCS which means it cannot store single user's configuration, because these will change from developer to developer since each one might have a different working environment.

As for the environment variables, it works, but feels more like an workaround than an actual solution.

@badsyntax
Copy link
Collaborator

Hey thanks for responding.

I agree with your first point.

For the second point, yes the point of gradle.properties being added to VCS is to provide a consistent environment for everyone working on the project. I do agree that org.gradle.java.home is something that could be different on different machines though.

About the environment variables, I feel this is the most consistent & standard way of configuring things. Developers will already be aware of these standard variables. Maybe it's not obvious to some how to change those variables on a per-project basis, but that's outside the scope of this extension.

But saying all of that, I think consistency is more important here. So if the vscode-java authors decided to control java configuration using non-standard vscode settings, then I should do the same, to provide better compatibility.

You've basically convinced me to a least support java.home 😃I am unsure about supporting other settings though (eg java.import.gradle.jvmArguments) as those settings imply they are only used for synchronizing gradle projects via buildship (which is used by the language server). I will think about this some more. But for now, I will make a change to support java.home.

@skypartan
Copy link
Author

That's great! I think it will simplify some of the initial work of setting up projects. Thanks for the help, and the extension!

@badsyntax
Copy link
Collaborator

badsyntax commented Apr 4, 2020

Cool 👍 Thanks for the feedback.

Some initial ideas about providing support for this setting:

Similar to vscode-java I will need to start the gradle server using java.home. Unlike vscode-java, I start this process using a shell script generated by CreateStartScripts. I will need to maybe use a custom start script template and provide java.home as either a custom ENV var or an argument to the start script to launch the server.

I'm unsure if i also need to specify this setting on the gradle ModelBuilder but if so I will need to either create a new argument for the server or read from custom ENV var as above, and make that value accessible so the handlers can read it.

badsyntax added a commit that referenced this issue Apr 10, 2020
Add support for custom java home setting. Refs #249
@badsyntax
Copy link
Collaborator

badsyntax commented Apr 10, 2020

I've got a working solution with #255

I've not being able to write tests for this (testing vscode extensions are hard) but I have verified it's working as expected by looking at the spawned java processes.

(Also sorry for the delay, due to the corona virus and various other reasons, it took me a long time to setup a windows VM to test the changes to the windows .bat startup script.)

I will release shortly so you can test this.

@badsyntax
Copy link
Collaborator

@skypartan this feature is now released with version 2.5.0

can you update the extension and see if this works for you?

i've added a note about this setting to the README here: https://github.com/badsyntax/vscode-gradle#extension-settings

@skypartan
Copy link
Author

Hey! I did a quick test here and it looks like it's working without errors, my tasks were executed with the jdk defined in settings.json. Thanks!

@badsyntax
Copy link
Collaborator

Good to hear, thanks!

Refs: microsoft/vscode-java-pack#347 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants