Gradle With Examples

Gradle is a project build and automation tool for java based applications; something like ivy, ant and maven. Build tools help us to reduce our development and test time and hence increase productivity.


Grunt and Gulp are two popular build and automation tools for javascript projects like NodeJS or jQuery. Gant is a build tool mainly used for Groovy based applications. SBT stands for Scala Build Tool. SBT is mainly used for Scala based applications.

Now-a-days, most of the java projects are using either maven or gradle build tools because of their benefits when compared to ant.

Before discussing about Gradle, first we will go through some shortcomings of ant and maven. Then we will discuss about why we need Gradle build tool to our projects.

Drawbacks of Ant

The following are main drawbacks of using ant build tools in our project.

  1. We need to write ant build scripts using XML. If we want to automate a complex project, then we need to write a lot of logic in XML files.
  2. When we execute complex and large project’s ant build, it produces a lot of verbose at console.
  3. There is no built-in ant project structure. Since we can use any build structure for our projects, new developers find it hard to understand the project struct and build scripts.
  4. It is very tough to write some complex logic using if-then-else statements.
  5. We need to maintain all jars with required version in version control. There is no support for dependency management.

Because of these many drawbacks, now-a-days most of the projects have restructured and they are using maven build tool. Even though Maven provides the following benefits compare to ant, but still it has some drawbacks.

Advantages of Maven

  1. Maven is an expressive, declarative, and maintainable build tool.
  2. All maven projects follow pre-defined structure. Even new developers find it easy to understand the project structure and start development quickly.
  3. We don’t need to maintain all jars with required version in version control. Maven will download all required jars at build time. Maven support for dependency management is one of the best advantage it has over ant.
  4. Maven gives us very modularized project structure.

Drawbacks of Maven

  1. Maven follows some pre-defined build and automation lifecycle. Sometimes it may not fit to our project needs.
  2. Even though we can write custom maven life cycle methods, but it’s a bit tough and verbose.
  3. Maven build scripts are a bit tough to maintain for very complex projects.

Maven has solved most of the ant build tool issues, but still it has some drawbacks. To overcome these issues, we need to use Gradle build tool. Now we can start our discussion on Gradle.

What is Gradle?

Gradle is an opensource build and automation tool for java based projects. Using Gradle, we can reduce project development time and increase productivity.

Gradle is a multi-language, multi-platform, multi-project and multi-channel build and automation software.

Gradle advantages

Gradle will provide the following advantages compared to ant and maven. That’s why all new projects are using Gradle as build tool.

  1. Like Maven, Gradle is also an expressive, declarative, and maintainable build Tool.
  2. Just like maven, Gradle also supports dependency management.
  3. Gradle provides very scalable and high-performance builds.
  4. Gradle provides standard project layout and lifecycle, but it’s full flexibility. We have the option to fully configure the defaults. This is where it’s better than maven.
  5. It’s very easy to use gradle tool and implement custom logic in our project.
  6. Gradle supports the project structure that consists of more than one project to build deliverable.
  7. It is very easy to integrate existing ant/maven project with Gradle.
  8. It is very easy to migrate from existing ant/maven project to Gradle.

Gradle combines most of the popular build tool plus points into a single build tool.

In simple terminology, Gradle is built by taking all the good things from ant, maven, ivy and gant.


That means Gradle combines best features of all popular build tools:

  • Ivy and ant power and flexibility
  • Maven’s easy to use, lifecycle management and dependency management
  • Gant’s build scripts

NOTE: Gant is a Groovy based build system that internally uses ant tasks. In Gant, we need to write build scripts in Groovy, but no XML. Refer it’s official website for more information.

Why we need to choose Gradle?

  1. Gradle’s build scripts are more readable, expressive and declarative.
  2. Gradle’s build scripts are written in simple Groovy, no XML. That means it use it’s own DSL based on Groovy script.
  3. It’s highly scalable for complex multi-module projects.
  4. Unlike Maven’s pom.xml, No need to write boilerplate XML Code
  5. It provides plugins for most of the IDEs like Eclipse, IntelliJ IDEA, Spring STS Suite etc.
  6. It is very easy to maintain even for multi-module complex projects.

What is Gradle’s Motto?

“Make the impossible possible, make the possible easy, and make the easy elegant”.

By reading the Gradle’s Motto, we can understand that main goal and advantages of Gradle build tool.

As of now, Gradle works as build and automation tool for the following projects.

  • Java/Scala/Groovy Based Projects
  • Android Projects
  • C/C++ Projects
  • JavaScript Based Projects

Now we are clear that Gradle is the best build and automation tool to use in our projects. We are going to use Gradle in my Spring Boot Tutorial. As of today, Gradle’s latest and stable version is 4.1 released on 07-Aug-2017. We are going to use this version to run our examples.

Gradle official website:

Gradle Install

Please follow the following steps to install Gradle in Windows systems.

    1. Download latest Gradle software from by clicking “Download Gradle 2.4” button as shown below
    2. what_is_gradle-

Once download is successfully, we can observe a zip file as shown below


    1. Extract zip file into local file system

Observe Gradle Home directory:


Observe Gradle BIN directory:


    1. Set the following System Variables

set GRADLE_HOME=D:gradle-2.4
set PATH=D:gradle-2.4bin;%PATH%

    1. Open CMD Prompt and check the Setup is done successfully or not.
    2. gradle_version_check

We can use either of the following two commands to know the Gradle version.

D:>gradle -v
D:>gradle --version

By observing this output at Command Prompt as shown in above screenshot, we can say that Gradle installation is successful.

That’s it for now. We will see some Gradle simple and complex examples in coming posts.

By admin

Leave a Reply

%d bloggers like this: