sdkman / sdkman-cli

The SDKMAN! Command Line Interface
https://sdkman.io
Apache License 2.0
5.97k stars 629 forks source link

Question: How to initialize SDKMAN in a subprocess? #1281

Closed algomaster99 closed 4 months ago

algomaster99 commented 4 months ago

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

alexanderankin commented 4 months ago

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.

algomaster99 commented 4 months ago

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.