gradle.plugin.zsh
729 bytes
1# Looks for a gradlew file in the current working directory
2# or any of its parent directories, and executes it if found.
3# Otherwise it will call gradle directly.
4function gradle-or-gradlew() {
5 # find project root
6 # taken from https://github.com/gradle/gradle-completion
7 local dir="$PWD" project_root="$PWD"
8 while [[ "$dir" != / ]]; do
9 if [[ -x "$dir/gradlew" ]]; then
10 project_root="$dir"
11 break
12 fi
13 dir="${dir:h}"
14 done
15
16 # if gradlew found, run it instead of gradle
17 if [[ -f "$project_root/gradlew" ]]; then
18 echo "executing gradlew instead of gradle"
19 "$project_root/gradlew" "$@"
20 else
21 command gradle "$@"
22 fi
23}
24
25alias gradle=gradle-or-gradlew
26compdef _gradle gradle-or-gradlew