Skip to content

Instantly share code, notes, and snippets.

@Fleshgrinder
Last active March 18, 2020 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fleshgrinder/4dea4a703e850fed44b6a6fe47876237 to your computer and use it in GitHub Desktop.
Save Fleshgrinder/4dea4a703e850fed44b6a6fe47876237 to your computer and use it in GitHub Desktop.
Script to execute Maven wrapper with jEnv and fallback to global Maven installation.
#!/usr/bin/env bash
set -Eeuo pipefail
JAVA_HOME=$(jenv javahome)
export JAVA_HOME
if [[ -f mvnw ]]; then
exec ./mvnw "$@"
else
readonly project_dir=$PWD
while [[ ! -f mvnw && "$PWD" != / ]]; do
cd .. || break
done
if [[ -f mvnw ]]; then
exec ./mvnw --projects "$(realpath --relative-to="$PWD" "$project_dir")" "$@"
else
cd "$project_dir"
exec /usr/local/bin/mvn "$@"
fi
fi
#!/usr/bin/env bash
set -Eeuo pipefail
mkdir -p ~/bin
curl -Lo ~/bin/mvn 'https://gist.githubusercontent.com/Fleshgrinder/4dea4a703e850fed44b6a6fe47876237/raw/mvn'
chmod +x ~/bin/mvn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment