halcyon / asdf-java

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

Allow unset ASDF_DIR environment variable #163

Closed SgtPooki closed 2 years ago

SgtPooki commented 2 years ago

Resolves the following error that displays for users who do not set ASDF_DIR:

$HOME/.asdf/plugins/java/bin/list-all: line 3: /lib/utils.bash: No such file or directory

As indicated in the official asdf docs, ASDF_DIR should default to ~/.asdf, though asdf itself defaults to $HOME/.asdf:

ASDF_DIR - Defaults to ~/.asdf - Location of the asdf scripts. If you install asdf to some other directory, set this to that directory. For example, if you are installing via the AUR, you should set this to /opt/asdf-vm.

halcyon commented 2 years ago

I'm trying to understand this use case. It looks like ASDF_DIR is set when asdf is loaded. https://github.com/asdf-vm/asdf/blob/master/asdf.sh#L14-L15

In what situation would ASDF_DIR not be set?

SgtPooki commented 2 years ago

In what situation would ASDF_DIR not be set?

There are a large number of circumstances that could result in ASDF_DIR not being set. Here are a few I can think of:

  1. https://github.com/asdf-community/asdf-direnv, which requires explicitly not sourcing asdf.sh so that the shims won't interfere. (my scenario)
  2. If asdf-vm stops setting ASDF_DIR
  3. The eventual event that always proves assumptions wrong.

This plugin has already seen two users (https://github.com/halcyon/asdf-java/issues/152) impacted by the assumption that ASDF_DIR is defined.

Either way, is not safeguarding a variable that you don't control a good idea?

halcyon commented 2 years ago

Thank you!