Skip to content

Instantly share code, notes, and snippets.

@floscher
Last active June 4, 2018 18:01
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 floscher/162c8559258550a4173a6c87b2454f47 to your computer and use it in GitHub Desktop.
Save floscher/162c8559258550a4173a6c87b2454f47 to your computer and use it in GitHub Desktop.
A script for updating an existing Gradle wrapper in a given directory to another version.
#!/usr/bin/env sh
if [ $# -ne 2 ]; then
echo "This script needs exactly two parameters: the path where the current Gradle wrapper is and the version to which to upgrade."
echo "Example: ./update_gradle_wrapper.sh ./path/to/directory/to/update/ 1.2.3"
exit 1;
fi
distType="all"
path="$1"
version="$2"
cd "$path"
# Execute 2 times, so the wrapper task is executed by the specified Gradle version (the first time the "old" version is used).
# Additionally this makes sure, that the specified Gradle version is downloaded and cached.
for i in 0 1; do
./gradlew wrapper --gradle-version="$version" --distribution-type="$distType"
done
# Remove comments
sed -i -e '/^#.*/d' gradle/wrapper/gradle-wrapper.properties
# Add SHA256 sum
shaSum=`sha256sum ~/.gradle/wrapper/dists/gradle-$version-$distType/*/gradle-$version-$distType.zip | cut -c 1-64`
printf "distributionSha256Sum=$shaSum" >> gradle/wrapper/gradle-wrapper.properties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment