halcyon / asdf-java

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

set-java-home.bash requires PWD change? #116

Open mgh520 opened 3 years ago

mgh520 commented 3 years ago

Curious why this was changed to only update JAVA_HOME if PWD has changed. Maybe I'm doing something wrong but I'm trying to do this:

asdf global java adoptopenjdk-8.0.275+1.openj9-0.23.0
. ~/.asdf/plugins/java/set-java-home.bash

the path changes, so java-version shows 1.8, but JAVA_HOME does not change because I haven't changed directories.

Use case is something like this:

  1. change to my project directory
  2. run maven/java command
  3. "crap, this one requires jdk 8, not 11"
  4. run commands above to switch to jdk 8
  5. JAVA_HOME is not changed and command still fails
NoSugarCoffee commented 1 year ago

same issue

looks like it was designed that way

// the code from `~/.asdf/plugins/java/set-java-home.bash`
function _asdf_java_prompt_command() {
  if [[ "${PWD}" == "${LAST_PWD}" ]]; then
    return
  fi
  LAST_PWD="${PWD}"
  _asdf_java_update_java_home
}
NoSugarCoffee commented 1 year ago

same issue

looks like it was designed that way

// the code from `~/.asdf/plugins/java/set-java-home.bash`
function _asdf_java_prompt_command() {
  if [[ "${PWD}" == "${LAST_PWD}" ]]; then
    return
  fi
  LAST_PWD="${PWD}"
  _asdf_java_update_java_home
}

Removing check condition seems to work, but I'm not sure if it makes sense

function _asdf_java_prompt_command() {
  #if [[ "${PWD}" == "${LAST_PWD}" ]]; then
  #  return
  #fi
  #LAST_PWD="${PWD}"
  _asdf_java_update_java_home
}