-
-
Save jdigger/7ff2c25d45eba5a2b585557db374daeb to your computer and use it in GitHub Desktop.
Gradle Wrapper search script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# PURPOSE | |
# | |
# The Gradle wrapper[1] is a simple and convenient way of making Gradle | |
# builds self-contained and reproducible. However, in multi-project | |
# builds, it can be cumbersome to type in relative paths e.g.: | |
# ./gradlew # when in root | |
# ../gradlew # when in subdir | |
# | |
# This script finds any Gradle wrapper (gradlew) executable in the | |
# current directory or any directory above it. | |
# | |
# | |
# DEBUGGING | |
# | |
# To observe the search for gradlew and to ensure which one is | |
# ultimately used, invoke the script with Bash's "-x" option. Below you | |
# can see the directory traversal at work, finally selecting the | |
# 'gradlew' script one directory up from where 'gradle' was invoked. | |
# | |
# $ cd /src/my-proj/submod | |
# $ bash -x $(which gw) --version | |
# + GRADLEW=/src/my-proj/submod/gradlew | |
# + GRADLEW=/src/my-proj/gradlew | |
# + /src/my-proj/gradlew --version | |
# ... | |
# | |
# | |
# [1] http://gradle.org/docs/current/userguide/gradle_wrapper.html | |
CWD=$PWD | |
until [ $CWD == / ]; do | |
GRADLEW=$CWD/gradlew | |
if [ -e $GRADLEW ]; then | |
exec $GRADLEW $@ | |
fi | |
CWD=$(dirname $CWD) | |
done | |
echo No Gradle wrapper found | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment