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.
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.
- 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.
- When we execute complex and large project’s ant build, it produces a lot of verbose at console.
- 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.
- It is very tough to write some complex logic using if-then-else statements.
- 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
- Maven is an expressive, declarative, and maintainable build tool.
- All maven projects follow pre-defined structure. Even new developers find it easy to understand the project structure and start development quickly.
- 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.
- Maven gives us very modularized project structure.
Drawbacks of Maven
- Maven follows some pre-defined build and automation lifecycle. Sometimes it may not fit to our project needs.
- Even though we can write custom maven life cycle methods, but it’s a bit tough and verbose.
- 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 will provide the following advantages compared to ant and maven. That’s why all new projects are using Gradle as build tool.
- Like Maven, Gradle is also an expressive, declarative, and maintainable build Tool.
- Just like maven, Gradle also supports dependency management.
- Gradle provides very scalable and high-performance builds.
- 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.
- It’s very easy to use gradle tool and implement custom logic in our project.
- Gradle supports the project structure that consists of more than one project to build deliverable.
- It is very easy to integrate existing ant/maven project with Gradle.
- 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?
- Gradle’s build scripts are more readable, expressive and declarative.
- Gradle’s build scripts are written in simple Groovy, no XML. That means it use it’s own DSL based on Groovy script.
- It’s highly scalable for complex multi-module projects.
- Unlike Maven’s pom.xml, No need to write boilerplate XML Code
- It provides plugins for most of the IDEs like Eclipse, IntelliJ IDEA, Spring STS Suite etc.
- 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
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: https://gradle.org/
Please follow the following steps to install Gradle in Windows systems.
- Download latest Gradle software from https://gradle.org/ by clicking “Download Gradle 2.4” button as shown below
Once download is successfully, we can observe a zip file as shown below
- Extract zip file into local file system
Observe Gradle Home directory:
Observe Gradle BIN directory:
- Set the following System Variables
- Open CMD Prompt and check the Setup is done successfully or not.
We can use either of the following two commands to know the Gradle version.
D:>gradle -v Or 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.