scalameta / metals-vscode

Visual Studio Code extension for Metals
https://marketplace.visualstudio.com/items?itemName=scalameta.metals#overview
Apache License 2.0
298 stars 75 forks source link

Use coursier for downloading Java #1450

Closed tgodzik closed 6 months ago

tgodzik commented 8 months ago

Currently, we use a combination of locate-java-home and Jabba to get Metals with Java setup. However, both of those options are not very well maintained.

Instead, I think we should work out a much more stable approach with Metals using its' own JVM.

This can be done using coursier, which would make us reuse any Java that was previously downloaded using it or via Scala CLI.

We would need to follow these steps:

  1. Check if coursier is on PATH (this is already implemented) and if not try to download the native image (as explained https://get-coursier.io/docs/cli-installation#native-launcher). We should make sure that it's not downloaded every time. We could possibly have a version inside the repo and update it when releasing. The cs executable can be kept in the metals extension directory.
  2. Download Java cs java --jvm 17 --setup
  3. Check Java Home cs java-home --jvm 17
  4. Start metals with that Java Home
  5. Bloop should use the exact same Java Home.
  6. We should add a simple setting that allows user to choose JVM version for Metals itself. (8/11/17/21) currently and ideally (17/21) later on when we migrate to new sockets in Metals server.
  7. javaHome setting would only be used for running bloopInstall or bsp launchers.

Questions: