feat(mvn): support using mvnw in multi-module projects (#9413)

This commit is contained in:
Arthur Maltson 2021-10-11 05:40:17 -04:00 committed by GitHub
parent f82aa81931
commit 9bd0ac9b00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,11 +1,17 @@
# Calls ./mvnw if found, otherwise execute the original mvn # Calls mvnw if found in the current project, otherwise execute the original mvn
mvn-or-mvnw() { mvn-or-mvnw() {
if [ -x ./mvnw ]; then local dir="$PWD"
echo "executing mvnw instead of mvn" while [[ ! -x "$dir/mvnw" && "$dir" != / ]]; do
./mvnw "$@" dir="${dir:h}"
else done
command mvn "$@"
if [[ -x "$dir/mvnw" ]]; then
echo "Running \`$dir/mvnw\`..." >&2
"$dir/mvnw" "$@"
return $?
fi fi
command mvn "$@"
} }
# Wrapper function for Maven's mvn command. Based on https://gist.github.com/1027800 # Wrapper function for Maven's mvn command. Based on https://gist.github.com/1027800
@ -17,6 +23,7 @@ mvn-color() {
local TEXT_BLUE=$(echoti setaf 4) local TEXT_BLUE=$(echoti setaf 4)
local TEXT_WHITE=$(echoti setaf 7) local TEXT_WHITE=$(echoti setaf 7)
local RESET_FORMATTING=$(echoti sgr0) local RESET_FORMATTING=$(echoti sgr0)
( (
# Filter mvn output using sed. Before filtering set the locale to C, so invalid characters won't break some sed implementations # Filter mvn output using sed. Before filtering set the locale to C, so invalid characters won't break some sed implementations
unset LANG unset LANG
@ -33,7 +40,7 @@ mvn-color() {
) )
} }
# either use orignal mvn or the mvn wrapper # either use original mvn or the mvn wrapper
alias mvn="mvn-or-mvnw" alias mvn="mvn-or-mvnw"
# Run mvn against the pom found in a project's root directory (assumes a git repo) # Run mvn against the pom found in a project's root directory (assumes a git repo)