Skip to content

Instantly share code, notes, and snippets.



Last active Jun 3, 2020
What would you like to do?
Simple script to update Gradle from the command line (*NIX)
# 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.
# 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
function printUsage {
echo "Usage: $0 [Gradle version, e.g., \"4.3\"]" >&2
echo "OPTIONS" >&2
echo " -h Prints usage info (this message)" >&2
if [[ $VERSION == -h ]]; then
exit 0
alias gw='./gradlew'
if [[ -z $VERSION ]]; then
# Fetch latest version from Gradle website
VERSION=$(curl "" 2>/dev/null | jq -r '.version')
if [[ -z $VERSION ]]; then
echo "Unable to fetch latest Gradle version, please try specifying it manually"
exit -1
echo "Upgrading Gradle to version: $VERSION"
gw wrapper --distribution-type=all --gradle-version=$VERSION && gw wrapper --distribution-type=all --gradle-version=$VERSION

This comment has been minimized.

Copy link
Owner Author

@rock3r rock3r commented Jun 3, 2020


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
You can’t perform that action at this time.