Introduction

In this article, we discuss Gradle and also have a look at its features, the installation guide, its advantages and create a simple program using Gradle.

What is Gradle

Gradle is built automation evolved. Gradle is a build system that offers you ease, power and freedom. You can choose the balance for yourself. It has powerful multi-project build support. It can automate the building, publishing, testing, deployment and more of software packages or other types of projects such as developing static websites, documentation or indeed anything else.
Gradle combines the power and flexibility of Apache Ant with the dependency management and conventions of Apache Maven into a more effective way to build. Powered by a Groovy DSL instead of the more traditional XML form of declaring the project configuration and packed with innovation, Gradle provides a declarative way to describe many kinds of builds through sensible defaults. Gradle is quickly becoming the build system of choice for many open source projects, leading-edge enterprises and legacy automation challenges. The initial plug-in is primarily focused around Java, Groovy and Scala development and deployment, but more languages and project workflows are on the roadmap.
To learn more about Gradle, including what it makes, get started with Gradle right now.
Download Gradle from the following link:
http://www.gradle.org/downloads

Gradle Installation

Step 1- First of all Gradle requires a Java JDK to be installed on your system. It requires a JDK 1.5 or higher version. It has its own Groovy library, so they don't require any other Groovy library. Any existing Groovy installation is ignored by Gradle.
It uses whichever JDK it finds in your path (for checking Java version, use the command "java -version"). Alternatively, we can set the JAVA_HOME environment variable to point to the install directory of the desired JDK.
For example:
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_21;
Step 2- Unpacking the zip file
After unpacking the downloaded zip file, the full distribution contains:
Step 3- Set the environment variable for Gradle.
To run Gradle, we must add GRADLE_HOME (the folder path of where we copied Gradle) to our PATH environment variable. Usually, this is sufficient to run Gradle.
In the path environment variable simply add GRADLE_HOME/bin (for example "E:\gradle\bin;").
Step 4: How to run or check the installation work or not?
To run Gradle we must use the "gradle" command. For checking that Gradle is properly installed just type "gradle -v". That shows the Gradle version and also the local environment configuration (Groovy and JVM version, etcetera). The displayed Gradle version should match the distribution you have downloaded.
The following figure shows the output of the gradle command:
Fig-1.jpg
When we run the command "gradle -v" it shows the version of Gradle installed in your system, as in the following figure:
Fig-2.jpg
Step 5- JVM Options
This option runs Gradle to set the environment variables. We can use JAVA_OPTN or GRADLE_OPTN. Both variables can be used together. JAVA_OPTN is an environment variable that can be shared by many Java applications.

Advantages of Gradle

Creating a simple program to print "Welcome To Gradle"
You run a Gradle script using the gradle command. The gradle command looks for a file called welcome.gradle in the current directory. We call this welcome.gradle file a build script, although strictly speaking it is a build configuration script, as we will see later. The build script defines a project and its tasks.
To try this out, create the following welcome script named welcome.gradle.
The first welcome script
Compilation
  1. task Welcome
  2. {
  3. doLast
  4. {
  5. println 'Welcome To Gradle!'
  6. }
  7. }
For compiling our program we have the command gradle -q Welcome:
Output
gradle -q Welcome
Welcome To Gradle!