others-how to upgrade gradle in MacOS with SDKMan

Problem

How to upgrade gradle in MacOS? This article would show the guide of how to install and upgrade gradle in Mac OS with SDKMAN.

Environment

  • Mac OS

Solution

Step 1: Install SDKMan

SDKMan is :

The Software Development Kit Manager

SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. It provides a convenient Command Line Interface (CLI) and API for installing, switching, removing and listing Candidates. Formerly known as GVM the Groovy enVironment Manager, it was inspired by the very useful RVM and rbenv tools, used at large by the Ruby community.

image-20201119210910415

Install SDKMan as follows:

curl -s "https://get.sdkman.io" | bash

After installation, make sure to execute the script: (change xxx to your username)

source "/Users/xxx/.sdkman/bin/sdkman-init.sh"

check the SDKMan installation by this command:

sdk help

Usage: sdk <command> [candidate] [version]
       sdk offline <enable|disable>

   commands:
       install   or i    <candidate> [version] [local-path]
       uninstall or rm   <candidate> <version>
       list      or ls   [candidate]
       use       or u    <candidate> <version>
       default   or d    <candidate> [version]
       home      or h    <candidate> <version>
       env       or e    [init]
       current   or c    [candidate]
       upgrade   or ug   [candidate]
       version   or v
       broadcast or b
       help
       offline           [enable|disable]
       selfupdate        [force]
       update
       flush             [archives|tmp|broadcast|version]

   candidate  :  the SDK to install: groovy, scala, grails, gradle, kotlin, etc.
                 use list command for comprehensive list of candidates
                 eg: $ sdk list
   version    :  where optional, defaults to latest stable if not provided
                 eg: $ sdk install groovy
   local-path :  optional path to an existing local installation
                 eg: $ sdk install groovy 2.4.13-local /opt/groovy-2.4.13

Step 2: Install grade with SDKMan

List gradle versions that SDKMan supports:

sdk list gradle  

Install specific gradle version with SDKMan:

sdk install gradle 6.7.1

Step 3: Switch or Upgrade to specific gradle version:

Use or switch to specific gradle version in current terminal shell:

sdk use gradle 6.7.1

The upper command only affect current shell, if you want to change your default settings, just do as follows:

sdk default gradle 6.7.1

Step 4: Check the install result

➜  ~ gradle --version

Welcome to Gradle 6.7.1!

Here are the highlights of this release:
 - File system watching is ready for production use
 - Declare the version of Java your build requires
 - Java 15 support

For more details see https://docs.gradle.org/6.7.1/release-notes.html


------------------------------------------------------------
Gradle 6.7.1
------------------------------------------------------------

Build time:   2020-11-16 17:09:24 UTC
Revision:     2972ff02f3210d2ceed2f1ea880f026acfbab5c0

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          1.8.0_121 (Oracle Corporation 25.121-b13)
OS:           Mac OS X 10.14.6 x86_64

BTW: Where is my gradle?

The gradle installed by SDKMan is in your home directory (~/.sdkman/candidates/gradle): (assume current user is bswen)

➜  ~ ll .sdkman/candidates/gradle
total 0
drwxr-xr-x  8 bswen  staff   256B Feb  1  1980 6.7.1
lrwxr-xr-x  1 bswen  staff     5B Nov 19 20:54 current -> 6.7.1
➜  ~

So ,you gradle home directory installed by SDKMan is: /Users/bswen/.sdkman/candidates/gradle/6.7.1