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

Unable to use local java version different from system-wide default for Metals #1558

Open
matteobilardi opened this issue Dec 11, 2024 · 1 comment · May be fixed by #1559
Open

Unable to use local java version different from system-wide default for Metals #1558

matteobilardi opened this issue Dec 11, 2024 · 1 comment · May be fixed by #1559

Comments

@matteobilardi
Copy link

Describe the bug

In an environment with no access to the internet, where I have both VSCode, the metals extension, java 11 and java 17 already installed, and java 11 is the default system-wide java version, it is not possible to run metals with a Scala project that requires exactly java 11 both for running and building.

To Reproduce
On ubuntu jammy

sudo apt install openjdk-17-jdk openjdk-11-jdk 
sudo update-alternatives --config java // Pick java-11-openjdk as the default java

Install vscode and the metals extension and open a scala project that requires java 11.
Disconnect from the internet.

Expected behavior

Currently, it is possible to set distinct java versions for metals and the project, e.g. via

metals.javaVersion: 17,
metals.javaHome: "/usr/lib/jvm/java-11-openjdk-amd64"

However, this only works if either java 17 is the system-wide java binary available in PATH or if there is an internet connection for coursier to use to download java. I would like to be able to tell metals to use the java version at /usr/lib/jvm/java-17-openjdk-amd64/bin/java to run itself, and the java home at /usr/lib/jvm/java-11-openjdk-amd64 to run the project, while at the same time not having java 17 being the default version of java available in PATH, and without having a connection to the internet. That is, I think that something like the following should be possible

metals.javaPath: "/usr/lib/jvm/java-17-openjdk-amd64/bin/java", // use this for metals
metals.javaHome: "/usr/lib/jvm/java-11-openjdk-amd64" // use this for the scala project

Installation:

  • Operating system: Linux
  • VSCode version: 1.94
  • VSCode extension version: 1.43.0
  • Metals version: 1.4.1

Additional context

Search terms

JAVA_HOME, javaVersion, javaHome, coursier, offline

@tgodzik
Copy link
Contributor

tgodzik commented Dec 11, 2024

Thanks for reporting! We should allow javaPath to be modified by the user. I will take a look at it. As a workaround you can set JAVA_HOME globally or just before starting VS Code from comman line via code .

tgodzik added a commit to tgodzik/metals-vscode that referenced this issue Dec 12, 2024
Peviously, if use had JAVA_HOME and java on PATH pointing to JDK 11, we would download JDK 17 using coursier. This however might not work if there is no internet and there was no way to work around that. Now, we allow users to specify an override for those cases.

Fixes scalameta#1558
tgodzik added a commit to tgodzik/metals-vscode that referenced this issue Dec 12, 2024
Peviously, if use had JAVA_HOME and java on PATH pointing to JDK 11, we would download JDK 17 using coursier. This however might not work if there is no internet and there was no way to work around that. Now, we allow users to specify an override for those cases.

Fixes scalameta#1558
@tgodzik tgodzik linked a pull request Dec 12, 2024 that will close this issue
tgodzik added a commit to tgodzik/metals-vscode that referenced this issue Dec 12, 2024
Peviously, if use had JAVA_HOME and java on PATH pointing to JDK 11, we would download JDK 17 using coursier. This however might not work if there is no internet and there was no way to work around that. Now, we allow users to specify an override for those cases.

Fixes scalameta#1558
tgodzik added a commit to tgodzik/metals-vscode that referenced this issue Dec 12, 2024
Peviously, if use had JAVA_HOME and java on PATH pointing to JDK 11, we would download JDK 17 using coursier. This however might not work if there is no internet and there was no way to work around that. Now, we allow users to specify an override for those cases.

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

Successfully merging a pull request may close this issue.

2 participants