How do I install Gradle in Mac OS X?

Gradle

In this post we will learn how to install Gradle in OS X. The following steps will guide our installation process to make Gradle available in our OS X machine. But before we start let’s take a look at the definition from wikipedia about Gradle.

Gradle is an open source build automation system that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the XML form used by Apache Maven of declaring the project configuration.

From: Wikipedia

I. Using Homebrew

The short and simple answer is to use the Homebrew package manager for macOS. You can visit the website for detail on how to install the Homebrew. But to help you, I’ve copied the online script to install it below:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

After installing Homebrew, just type the following command to install Gradle.

brew install gradle

Now, if you want to do it manually, here are the steps 😉

II. Manual Installation Steps

1. Download Gradle

To download visit Gradle Releases Page. Download the complete distribution which includes binaries, sources and offline documentation. For example, you can download the latest release of Gradle, as of this update the version is gradle-4.0.2-all.zip.

2. Unpacking Gradle and Configure Environment Variables

  • Open Terminal.app.
  • Create a new directory sudo mkdir /usr/local/gradle.
  • Extract the downloaded Gradle distribution archive by executing sudo unzip gradle-4.0.2-all.zip -d /usr/local/gradle.
  • Edit .bash_profile in your home directory to add GRADLE_HOME variable with the following line export GRADLE_HOME=/usr/local/gradle/gradle-4.0.2
  • Also update the PATH variable to include $GRADLE_HOME/bin. If you don’t already have the PATH variable add the following line export PATH=$GRADLE_HOME/bin:$PATH
  • Run source ~/.bash_profile to executes the update version of .bash_profile. Or you can open a new Terminal.app to make this changes active.

3. Running the Installation

To test Gradle installation open the Terminal.app and execute gradle -v command. If your installation was correct you will see something like the following output:

$ gradle -v

------------------------------------------------------------
Gradle 4.0.2
------------------------------------------------------------

Build time:   2017-07-26 15:04:56 UTC
Revision:     108c593aa7b43852f39045337ee84ee1d87c87fd

Groovy:       2.4.11
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_121 (Oracle Corporation 25.121-b13)
OS:           Mac OS X 10.12.6 x86_64
Wayan

17 Comments

  1. Thanks Wayan for such an amazing help. However I have one question.

    After installation was done and when I executed the command “gradle -v” though it showed the proper version but there was warning as well. Could you please comment on this warning (pasting it below for your reference).

    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/usr/local/Cellar/gradle/4.4.1/libexec/lib/groovy-all-2.4.12.jar) to method java.lang.Object.finalize()
    WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
    WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
    WARNING: All illegal access operations will be denied in a future release
    
    
    
    Gradle 4.4.1
    
    Build time:   2017-12-20 15:45:23 UTC
    Revision:     10ed9dc355dc39f6307cc98fbd8cea314bdd381c
    
    Groovy:       2.4.12
    Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
    JVM:          9.0.1 (Oracle Corporation 9.0.1+11)
    OS:           Mac OS X 10.10.5 x86_64
    
    Reply
  2. Manual Installation isn’t working fine for me. I have created folder structure as it is and exported PATH as well but it isn’t working fine.

    Reply
    • Hi Muniraj,

      Have you update the $PATH variable to include the path to your Gradle installation? To make it permanent you can set it in your .bash_profile.

      export GRADLE_HOME=/usr/local/gradle/gradle-4.0.2
      export PATH=$GRADLE_HOME/bin:$PATH
      
      source ~/.bash_profile
      
      Reply
  3. Hi Wayan Saryada

    I have issue with unzipping, the gradle file its in the downloads and tried the sudo unzip but it says
    unzip: cannot find or open gradle-5.4.1-bin.zip, gradle-5.4.1-bin.zip.zip or gradle-5.4.1-bin.zip.ZIP.

    Reply
  4. I was facing issue setting the gradle version globally in bash_profile file, I added the export statements inside .zshrc file, it solved the issue

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.