• Get In Touch
April 2, 2017

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:

  • Declarative builds and build-by-convention
  • Structure your build
  • Language for dependency based programming
  • Multi-project builds
  • Gradle scales
  • Deep API
  • Ease of migration
  • Gradle is the first build integration tool
  • Many ways to manage your dependencies
  • The Gradle wrapper

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

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]