My HP

2nd April, 2017 | Tutorials |

How to Install Gradle on CentOS 7

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.

Get a Cloud Server

Gradle is a free and open source build toolset system based on the concepts of Apache Ant and Apache Maven. Gradle provides powerful support for multi projects builds. It also provides full support for your existing Maven or Ivy repository infrastructure. Some of it's features are listed below:

Prerequisites

You'll need a CentOS 7 server and root user privileges over it to follow this tutorial to install Gradle oyour server. you can switch from non root user to root user using sudo -i command.

Update the System

Before going through the installation process it is highly recommended to update your system first and upgrade all available packages. To do so simply run below shown command it'll do the job for you.

yum -y update yum -y install epel-release

Install JDK

Gradle requires Java Development Kit to work. So we will have to first install JDK and we can install JDK 8 using following command.

yum -y install java-1.8.0-openjdk

We have installed JDK now it is better to verify the installation using following command.

java -version

You should see following output on your screen.

openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)

Install Gradle

We have installed all the dependencies required to install Gradle now we are ready to download and install it on your server. So first of all download the latest version of Gradle. Run the following command to download Gradle to your system.

wget https://services.gradle.org/distributions/gradle-3.4.1-bin.zip

Now we have downloaded Gradle on your system now create a directory for installation.

mkdir /opt/gradle

Next, extract the downloaded archive file into the above directory that we just created using following command.

unzip -d /opt/gradle gradle-3.4.1-bin.zip

Next, you'll have to set path environment variable for Gradle so it can be directly executed anywhere on the system.

export PATH=$PATH:/opt/gradle/gradle-3.4.1/bin

It is better to verify the installation sorun following command to check version of Gradle and you should see following output like shown below. gradle -v

------------------------------------------------------------
Gradle 3.4.1
------------------------------------------------------------

Build time: 2017-03-03 19:45:41 UTC Revision: 9eb76efdd3d034dc506c719dac2955efb5ff9a93

Groovy: 2.4.7 Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015 JVM: 1.8.0_121 (Oracle Corporation 25.121-b13) OS: Linux 3.10.0-514.10.2.el7.x86_64 amd64

Creating New Gradle Builds

You can now create new Gradle builds and for that you need to be able to identify the project type and how such a project is structured. Here we will create a project skeleton using Gradle build file. Run the following commands to cretae a basic java project.

mkdir test cd test gradle init --type java-library

Now when you'll check test directory you'll see that it has created a number of files and directories.

├── build.gradle
├── gradle
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src

You can now edit this build.gradle file and source files too.

Gradle Command Line

You can execute multiple tasks in a single build by listing each of the tasks on the command-line.Executing multiple tasks:

task compile {
    doLast {
        println 'compiling source'
    }
}

task compileTest(dependsOn: compile) { doLast { println 'compiling unit tests' } }

task test(dependsOn: [compile, compileTest]) { doLast { println 'running unit tests' } }

task dist(dependsOn: [compile, test]) { doLast { println 'building the distribution' } }

The output should look like this:

> gradle dist test
:compile
compiling source
:compileTest
compiling unit tests
:test
running unit tests
:dist
building the distribution

BUILD SUCCESSFUL

Dry Run

Sometimes you need to know which tasks are executed in which order for a given set of tasks specified on the command line, but you don't want the tasks to be executed. You can use the -m option for this. For example, if you run “gradle -m clean compile”, you'll see all the tasks that would be executed as part of the clean and compile tasks. This is complementary to the tasks, which shows you the tasks which are available for execution.

Conclusion

In this tutorial you've learned how to install Gradle on your CentOS 7 server.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.

Get a Cloud Server

Comments