Skip to content

Instantly share code, notes, and snippets.

@rock3r
Last active June 30, 2023 01:27
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rock3r/277d5c4ee212bd53bac07ac3b5b84a12 to your computer and use it in GitHub Desktop.
Save rock3r/277d5c4ee212bd53bac07ac3b5b84a12 to your computer and use it in GitHub Desktop.
Simple script to update Gradle from the command line (*NIX)
#!/bin/sh
# License for any modification to the original (linked below):
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# Sebastiano Poggi wrote this file. As long as you retain
# this notice you can do whatever you want with this stuff. If we meet some day,
# and you think this stuff is worth it, you can buy us a beer in return.
#### SETUP/USAGE INSTRUCTIONS ####
# 1. Save this to your computer, somewhere on your $PATH
# 2. Rename to gw-update (take out the .sh extension)
# 3. Open a terminal and make it executable:
# $ chmod a+x gw-update
# 4. Run it from your project root dir, specifying a target Gradle version:
# $ gw-update 4.3
VERSION=$1
function printUsage {
echo
echo "Usage: $0 [Gradle version, e.g., \"4.3\"]" >&2
echo
echo "OPTIONS" >&2
echo " -h Prints usage info (this message)" >&2
}
if [[ $VERSION == -h ]]; then
printUsage
exit 0
fi
alias gw='./gradlew'
if [[ -z $VERSION ]]; then
# Fetch latest version from Gradle website
VERSION=$(curl "https://services.gradle.org/versions/current" 2>/dev/null | jq -r '.version')
if [[ -z $VERSION ]]; then
echo "Unable to fetch latest Gradle version, please try specifying it manually"
printUsage
exit -1
fi
fi
echo "Upgrading Gradle to version: $VERSION"
gw wrapper --distribution-type=all --gradle-version=$VERSION && gw wrapper --distribution-type=all --gradle-version=$VERSION
@rock3r
Copy link
Author

rock3r commented Jun 3, 2020

Changelog

v2.0 (3 Jun 2020)

  • Add ability to fetch current Gradle version automatically when no version is specified

Note: Gradle is actually run twice when updating, the first time to download the new version, and the second time to force it to update the wrapper itself, which it doesn't automatically do when downloading the new version.

v1.0 (30 Oct 2017)

  • Initial version, requires explicit Gradle version to be provided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment