Skip to content

Instantly share code, notes, and snippets.

@tehlers
Created May 27, 2015 07:42
Show Gist options
  • Save tehlers/3a9944ff751a17280732 to your computer and use it in GitHub Desktop.
Save tehlers/3a9944ff751a17280732 to your computer and use it in GitHub Desktop.
This script will execute the Gradle wrapper, if it is available in the current or a parent directory. Otherwise it will fall back to start the Gradle version found in $PATH. The intended way to use this script is as an alias for 'gradle'.
#! /usr/bin/env bash
#
# This script will execute the Gradle wrapper, if it is available in the current
# or a parent directory. Otherwise it will fall back to start the Gradle version
# found in $PATH.
#
# The intended way to use this script is as an alias for 'gradle'.
#
WORK_DIR=$(pwd)
while [[ $PWD != / ]]; do
WRAPPER=$(find "$PWD"/ -maxdepth 1 -name "gradlew")
if [ -n "$WRAPPER" ]; then
break
fi
cd ..
done
cd "$WORK_DIR"
if [ -n "$WRAPPER" ]; then
$WRAPPER "$@"
else
gradle "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment