halcyon / asdf-java

A Java plugin for asdf-vm.
MIT License
466 stars 86 forks source link

set JAVA_HOME in exec-env #148

Closed mpern closed 3 years ago

mpern commented 3 years ago

IMHO the plugin should set JAVA_HOME for all commands.

Bonus:

Exporting JAVA_HOME in exec-env makes the plugin play nice with asdf-direnv

joschi commented 3 years ago

@mpern How would users be able to override the JAVA_HOME environment variable manually? In which cases would the exec-env script be executed?

Just wondering if this change would have adverse effects on users of asdf-java.

mpern commented 3 years ago

Maybe it's just me, but I do not want to manage JAVA_HOME manually.

Setup the env to run the binaries in the package. Source: https://asdf-vm.com/#/plugins-create?id=binexec-env

You use set-env to setup all env vars as required for the binaries (and as consequence, for the shims generated by asdf)

asdf-direnv uses the exec-env script to prepare the per-directory environment based on the .tools-version file in that dir.

e.g.

cd project-foo
direnv: using asdf nodejs lts
direnv: using asdf java sapmachine-11.0.11
direnv: using asdf direnv 2.28.0
direnv: export +JAVA_NOME ~PATH
vic commented 3 years ago

not sure when would a user want to set JAVA_HOME to something different than the value provided by this plugin's exec-env. it makes no sense to use the tools provided by this plugin and use a totally different location for JAVA_HOME.

anyways if we'd like users to be able to set their java home we could have the exec-env file do something like export JAVA_HOME="${JAVA_HOME:-"this_plugin_installation_java_home"}"

joschi commented 3 years ago

not sure when would a user want to set JAVA_HOME to something different than the value provided by this plugin's exec-env. it makes no sense to use the tools provided by this plugin and use a totally different location for JAVA_HOME.

Imagine a user would like to start a program with a different JAVA_HOME because it requires a JDK which isn't supported by asdf-java.

But I think I misunderstood how exec-env is working in the first place. If the java (or any other) shim isn't executed, the exec-env script wouldn't be executed, would it?

anyways if we'd like users to be able to set their java home we could have the exec-env file do something like export JAVA_HOME="${JAVA_HOME:-"this_plugin_installation_java_home"}"

Yes, this could be an option. 👍

mpern commented 3 years ago

But I think I misunderstood how exec-env is working in the first place. If the java (or any other) shim isn't executed, the exec-env script wouldn't be executed, would it?

exactly!

exec-env is for shims etc. managed by asdf

mpern commented 3 years ago

Let's get this merged please :slightly_smiling_face: