Gradle is an open source build automation system used primarily for Java projects.
It combines the best features of Ant and Maven. Unlike its predecessors which use XML for scripting, Gradle uses Groovy, a dynamic, object-oriented programming language for the Java platform to define the project and build scripts.
This tutorial outlines the steps necessary to install the latest version of Gradle on CentOS 7 systems.
1. Install Java JDK
Gradle requires Java JDK or JRE version 7 or above to be installed.
Install the OpenJDK 8 package with the following command:
$ sudo yum install java-1.8.0-openjdk-devel
2. Downloading the Gradle Binary
In this article, the latest version of Gradle is 5.0
. Before continuing with the next step you should check the Gradle releases page to see if a newer version is available.
Start by downloading the Gradle Binary-only zip file in the /tmp
directory using the following wget
command:
$ wget https://services.gradle.org/distributions/gradle-5.0-bin.zip -P /tmp
When the download is complete, extract the zip file in the /opt/gradle
directory:
$ sudo unzip -d /opt/gradle /tmp/gradle-5.0-bin.zip
Verify that the Gradle files are extracted by listing the /opt/gradle/gradle-5.0
directory:
$ ls /opt/gradle/gradle-5.0
bin getting-started.html init.d lib LICENSE media NOTICE
3. Setup environment variables
The next step is to configure the PATH environment variable to include the Gradle bin directory. To do so, open your text editor and create a new file named gradle.sh
inside of the /etc/profile.d/
directory.
$ sudo nano /etc/profile.d/gradle.sh
Paste the following configuration:
/etc/profile.d/gradle.sh
$ export GRADLE_HOME=/opt/gradle/gradle-5.0
$ export PATH=${GRADLE_HOME}/bin:${PATH}
Save and close the file. This script will be sourced at shell startup.
Make the script executable by typing:
$ sudo chmod +x /etc/profile.d/gradle.sh
Load the environment variables using the following command:
$ source /etc/profile.d/gradle.sh
4. Verify the Gradle installation
To validate that Gradle is installed properly use the gradle -v
command which will display the Gradle version:
You should see something like the following:
Welcome to Gradle 5.0!
Here are the highlights of this release:
- Kotlin DSL 1.0
- Task timeouts
- Dependency alignment aka BOM support
- Interactive `gradle init`
For more details see https://docs.gradle.org/5.0/release-notes.html
------------------------------------------------------------
Gradle 5.0
------------------------------------------------------------
Build time: 2018-11-26 11:48:43 UTC
Revision: 7fc6e5abf2fc5fe0824aec8a0f5462664dbcd987
Kotlin DSL: 1.0.4
Kotlin: 1.3.10
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_191 (Oracle Corporation 25.191-b12)
OS: Linux 3.10.0-862.14.4.el7.x86_64 amd64
If you hit a problem or have feedback, leave a comment below.