Installing Gradle

Explains how to install and configure Gradle so it can be used.

Gradle binary files are distributed from the Gradle website. However, many people probably will not use a method such as downloading files and placing them manually.

Gradle supports various package management tools. This page explains installation methods using representative package management tools for Windows and macOS.

Installing Gradle on Windows

On Windows, package management tools cannot be said to be widely established separately. Most people probably have not prepared anything like that.

Installing Scoop

Gradle supports a Windows package management tool called “Scoop”. First, install Scoop. This is done in PowerShell. Start PowerShell and run the following command.

iex (new-object net.webclient).downloadstring('https://get.scoop.sh')

This installs Scoop. If you do not know how to start PowerShell, right-click the Start menu, select the Run menu, enter “powershell”, and run it. A PowerShell window will open.

Installing Gradle with Scoop

After Scoop is installed, install Gradle. Open Command Prompt and run the following command.

scoop install gradle

After waiting for a while, installation is complete. There is no need to configure the path variable separately.

Installing Gradle on macOS

This section explains installation on macOS. On macOS as well, using a package management tool is the easiest method.

Installing Homebrew

On macOS, a package management tool called “Homebrew” is widely used. It is best to use this.

To use Homebrew, Java and Xcode must be installed. Java is probably already installed, but if Xcode is not available, install it. It can be installed from the App Store. Search for “xcode” to find it quickly.

When ready, start Terminal and run the following command.

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

This installs Homebrew. As you can see from the command, it uses Ruby. macOS includes Ruby by default, so no separate preparation is needed.

Installing Gradle with brew

When preparation is complete, install Gradle. Start Terminal and run the following.

$ brew update && brew install gradle

After waiting for a while, Gradle will be installed.

Installing with MacPorts

You can also use another package management tool called MacPorts. If you use it, run the following in Terminal.

$ sudo port install gradle

Enter the administrator password, and Gradle installation will run. Gradle installed by either method is the same.

Binary Installation

If you are not familiar with package management tools and want a simpler method, download the binary file and install it manually.

https://gradle.org/releases/

This is the download page on the Gradle website. Visit it and download the latest binary file from the “Releases” section. It is provided as an archive file, so extract it and place it in an appropriate folder.

Also, to use the Gradle command, you must add the path to the bin folder inside it to the path variable. Add the gradle-x.x\bin folder to the environment variable path.

GRADLE_HOME={GRADLE_HOME}\bin

After installation, start Command Prompt or Terminal and run the following.

$ gradle -v

If Gradle version information is displayed, installation was successful.

------------------------------------------------------------
Gradle 4.1
------------------------------------------------------------

Build time:   2017-08-07 14:38:48 UTC
Revision:     941559e020f6c357ebb08d5c67acdb858a3defc2

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.10.5 x86_64

Other Gradle Environment Variable Changes

  • You can pass JVM environment variables to set DEFAULT_JVM_OPTS= in the GRADLE_HOME\bin\gradle.bat file.
  • You can also pass JVM environment variables through JAVA_OPTS or GRADLE_OPTS.
set DEFAULT_JVM_OPTS=-Dfile.encoding=UTF-8 -Xmx512m -XX:PermSize=64m -XX:MaxPermSize=256m

Is Groovy Installation Required to Use Gradle?

Gradle was described as running on Groovy, so you might wonder whether Gradle cannot be used without installing Groovy. However, there is no need to worry.

Gradle includes Groovy from the beginning. Therefore, you do not need to install Groovy separately.

However, you cannot use Gradle’s embedded Groovy to create programs as a language, because the embedded Groovy is not exposed externally. Therefore, if you also want to learn and use Groovy, you need to install it separately.

http://groovy-lang.org/download.html

The URL above is Groovy’s website. Download the latest version from the download page. Like Gradle, it is distributed as an archive file.

After downloading, extract the archive and place the files in an appropriate location. Then add the path to the bin folder inside the saved folder to the path variable. After that, you can use Groovy.

When installation is complete, start Command Prompt or Terminal and run the following.

$ groovy -v

Use this to check whether the Groovy version is displayed. If it is displayed correctly, installation was successful.