How to install and configure Gradle on CentOS 7

Gradle is a general purpose build tool mainly used for Java projects. Gradle combines the best features of Ant and Maven. Unlike its predecessors that used XML for scripts, Gradle uses Groovy, a dynamic, object-oriented programming language for the Java platform to define projects and build scripts.

In this tutorial we will show you how to install Gradle on CentOS 7.

precondition

To install packages on a CentOS system, you must be logged in as a user with sudo privileges.

Install Gradle on CentOS 7

The following sections provide step by step instructions on how to install the latest version of Gradle on CentOS 7. We will download the latest version of Gradle from their official website.

1. Install OpenJDK

Gradle requires the Java JDK or JRE version 7 or higher to be installed. We will install OpenJDK 8.

Installing Java on CentOS 7 is very simple. Install the OpenJDK 8 package by typing:

sudo yum install java-1.8.0-openjdk-devel

Verify that Java is installed by running the following command which will print the Java version:

java -version

The output will look like this:

openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

2. Download Gradle

At the time of writing this article, it is the latest version of Gradle 5.2.1. Before proceeding with the next step, you should check the Gradle version page to see if a newer version is available.

Start by downloading the Gradle Binary-only zip file in the directory /tmp Use command wget next:

wget https://services.gradle.org/distributions/gradle-5.2.1-bin.zip -P /tmp

After the download is complete, extract the zip file in the directory /opt/gradle:

sudo unzip -d /opt/gradle /tmp/gradle-*.zip

Verify that the Gradle files have been extracted by listing directories /opt/gradle/gradle-5.2.1:

ls /opt/gradle/gradle-5.2.1
bin  getting-started.html  init.d  lib  LICENSE  media  NOTICE

3. Set environment variables

Next, we need to configure the PATH environment variable to include the directory where Gradle is stored. To do this, open a text editor and create a new file with the name gradle.sh inside the directory /etc/profile.d/

sudo nano /etc/profile.d/gradle.sh

Paste the following configuration:

export GRADLE_HOME=/opt/gradle/gradle-5.2.1
export PATH=${GRADLE_HOME}/bin:${PATH}

Save and close the file. The source of this script will be determined when the shell starts. Make the script executable by writing:

sudo chmod +x /etc/profile.d/gradle.sh

Then load the environment variables with the command source :

source /etc/profile.d/gradle.sh

4. Verify that Gradle is installed

To check that Gradle is installed correctly, use the command gradle -v which will show the Gradle version:

gradle -v

You will see the output as follows:

Welcome to Gradle 5.2.1!

Here are the highlights of this release:
 - Define sets of dependencies that work together with Java Platform plugin
 - New C++ plugins with dependency management built-in
 - New C++ project types for gradle init
 - Service injection into plugins and project extensions

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


------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------

Build time:   2019-02-08 19:00:10 UTC
Revision:     f02764e074c32ee8851a4e1877dd1fea8ffb7183

Kotlin DSL:   1.1.3
Kotlin:       1.3.20
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_181 (Oracle Corporation 25.181-b13)
OS:           Linux 4.9.0-8-amd64 amd64

At this point, your CentOS system has the latest version of Gradle installed.

See also  How to install and configure R on CentOS 8

conclusion

You have successfully installed Gradle on CentOS 7. You can now visit the official Gradle documentation page and learn how to get started with Gradle.

Source link