sdkman/sdkman-cli

Question: How to initialize SDKMAN in a subprocess?

algomaster99 opened this issue · 2 comments

Question

I am running a java subprocess in my test suite, but the test fails with error that it could not find java because sdkman initializes in ~/.zshrc and the path is also updated then.

However, if we symplink ~/.sdkman/candidates/java/current/bin/java to /usr/bin/java, it should also be detected in a subprocess. Is there a better solution than this? I don't want to source my sdkman-init.sh before the test.

System info

  • OS (e.g. Windows, Linux, Mac, Cygwin, WSL, etc.) Ubunut 22.04
  • Shell and version (e.g. bash --version/zsh --version)
zsh 5.8.1 (x86_64-ubuntu-linux-gnu)
  • The output of sdk version
SDKMAN!
script: 5.18.2
native: 0.4.6

I don't want to source my sdkman-init.sh before the test.

you should just pass PATH to your subprocess. in your main process, it found the right java in the PATH, right? so let is use the same PATH value in your subprocess.

Thanks, this helped!

it found the right java in the PATH, right?

I had to set the PATH manually in IntelliJ runner configuration and then it worked.