fabric8-analytics-vscode-extension icon indicating copy to clipboard operation
fabric8-analytics-vscode-extension copied to clipboard

[BUG] plugins fails when JAVA_HOME (or mvn) is not in the env/PATH

Open glhez opened this issue 4 years ago • 3 comments
trafficstars

Describe the bug The use maven to get dependencies, and maven requires JAVA_HOME. If JAVA_HOME Is not in the env, then mvn fails.

To Reproduce Steps to reproduce the behavior:

  1. Ensure that JAVA_HOME is not set
  2. Ensure that, in Settings, maven.executable.path is set to a valid maven executable path
  3. Try to execute: it will fail telling JAVA_HOME does not exists.

Expected behavior I would expect the extension to use the configured java.home (a settings in the Java extensions), or at least allows us to configure it alongside the maven.executable.path

*VSCodium:

  • Version: 1.54.3 (user setup)
  • Commit: 2b9aebd5354a3629c3aba0a5f5df49f43d6689f8
  • Date: 2021-03-16T00:26:40.437Z
  • Electron: 11.3.0
  • Chrome: 87.0.4280.141
  • Node.js: 12.18.3
  • V8: 8.7.220.31-electron.0
  • OS: Windows_NT x64 10.0.19042
  • Dependency Analytics Version [e.g. 0.3.2]

Additional context I do take care to NOT set environment variable on Windows, especially given how it is hard to access them when not admin. Beside, when you work with multiple JDK, it does not help. As an alternative to a java.home, I created a mvn-java11.cmd setting the appropriate JAVA_HOME.

I do think this is a bug, but that's also a feature request :)

glhez avatar Mar 25 '21 20:03 glhez

I use sdkman to handle Java and Maven.

My .bashrc contains the following code

export SDKMAN_DIR=/opt/sdkman
. /opt/sdkman/bin/sdkman-init.sh

In VSCode I configure the terminal to be interactive (so my .bashrc is executed)

    // Ensure VS Code uses the right shell for terminals and tasks.
    "terminal.integrated.defaultProfile.linux": "bash",
    "terminal.integrated.profiles.linux": {
      "bash": {
        "path": "/bin/bash",
        "args": [
          // Run interactive bash shell in VSCode integrated terminal
          "-i",
        ]
      }
    },

This way I can run java and mvn inside any VSCode terminal without problem but looks like fabric8-analytics-vscode-extension is not run in a VSCode terminal and so is not inheriting my configuration so it fails to find java and mvn.

I think that this extension should be run in a VSCode terminal inheriting user configuration.

rubensa avatar Apr 25 '22 10:04 rubensa

NOTE: To make the extension to work for now if you, like me, are using sdkman, you can set JAVA_HOME environment variable to $SDKMAN_DIR/candidates/java/current/ (here you must replace $SDKMAN_DIR with it's actual value) and maven.executable.path config property to $SDKMAN_DIR/candidates/maven/current/bin/mvn (here you can keep the $SDKMAN_DIR env variable)

rubensa avatar Apr 25 '22 11:04 rubensa

Update: You also need to replace $SDKMAN_DIR in maven.executable.path with current value as otherwise vscjava.vscode-maven extension fails to run.

rubensa avatar Apr 25 '22 13:04 rubensa

The latest versions of mvn do not require the specification of JAVA_HOME. Just make sure you have mvn installed on the system path or specify an alternative path in the extension settings.

IlonaShishov avatar Dec 25 '23 15:12 IlonaShishov