If you want to save time by writing less test code, take a look at my upcoming Test With Spring Course.

Getting Started With Gradle: Introduction

Easy way and hard way sign

Gradle is a build tool which replaces XML based build scripts with an internal DSL which is based on Groovy programming language.

It has gained a lot of traction recently and that is I why I decided to take a closer look at it.

This blog post is the first part of my Gradle tutorial, and this blog post has two goals:

  1. help us to install Gradle
  2. describe some of its basic concepts which helps us to understand the future parts of this tutorial.

Let’s start by finding out how we can install Gradle.

Installing Gradle

If we are using Windows or Linux, we can install Gradle by following these steps:

  1. Download the binaries from the downloads page.
  2. Unpack the zip file and add the GRADLE_HOME/bin directory to the PATH environment variable.

If we are using OS X, we can install Gradle by using Homebrew. We can do this by running the following command at command prompt:

brew install gradle

We can verify that Gradle is working properly by running the command gradle -v at command prompt. If Gradle is working properly, we should the following output (Windows and Linux users will naturally see a bit different output):

> gradle -v

Gradle 1.12

Build time:   2014-04-29 09:24:31 UTC
Build number: none
Revision:     a831fa866d46cbee94e61a09af15f9dd95987421

Groovy:       1.8.6
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
Ivy:          2.2.0
JVM:          1.8.0 (Oracle Corporation 25.0-b70)
OS:           Mac OS X 10.9.3 x86_64

Let’s take a quick look at the basic concepts of a Gradle build.

A Short Introduction to Gradle Build

Gradle has two basic concepts: projects and tasks. These concepts are explained in the following:

  • A project is either something we build (e.g. a jar file) or do (deploy our application to production environment). A project consists of one or more tasks.
  • A task is an atomic unit work which is performed our build (e.g. compiling our project or running tests).

So, how are these concepts related to a Gradle build? Well, every Gradle build contains one or more projects.

The relationships between these concepts are illustrated in the following figure:


We can configure our Gradle build by using the following configuration files:

  • The Gradle build script (build.gradle) specifies a project and its tasks.
  • The Gradle properties file (gradle.properties) is used to configure the properties of the build.
  • The Gradle Settings file (gradle.settings) is optional in a build which has only one project. If our Gradle build has more than one projects, it is mandatory because it describes which projects participate to our build. Every multi-project build must have a settings file in the root project of the project hierarchy.

Let’s move on and find out how we can add functionality to a Gradle build by using Gradle plugins.

Even Shorter Introduction to Gradle Plugins

The design philosophy of Gradle is that all useful features are provided by Gradle plugins. A Gradle plugin can:

  • Add new tasks to the project.
  • Provide a default configuration for the added tasks. The default configuration adds new conventions to the project (e.g. the location of source code files).
  • Add new properties which are used to override the default configuration of the plugin.
  • Add new dependencies to the project.

We can apply a Gradle plugin (this term is used when we add a plugin to a project) by using either its name or type.

We can apply a plugin by name (the name of the plugin is foo) by adding the following line to the build.gradle file:

apply plugin: 'foo'

On the other hand, if we want to apply a plugin by type (the type of the plugin is com.bar.foo), we must add the following line to the build.gradle file:

apply plugin: 'com.bar.foo'

That’s all for today. Let’s summarize what we learned from this blog post.


This blog post has taught us three things:

  • We learned how we can install Gradle.
  • We understand the basic building blocks of a Gradle build.
  • We know how we can add functionality to our build by using Gradle plugins.

The next part of this tutorial describes how we can create a simple Java project by using Gradle.

If you want to learn how to use Gradle, you should take a look at my Gradle tutorial.

About the Author

Petri Kainulainen is passionate about software development and continuous improvement. He is specialized in software development with the Spring Framework and is the author of Spring Data book.

About Petri Kainulainen →

14 comments… add one

  • I strongly recommend you take a closer look at gradle

    • I will do that.

  • Good post! Will you update more articles about Gradle?

    • Thanks! I really appreciate your kind words.

      And yes, I am going to write a Gradle tutorial which covers the essential parts of Gradle. This tutorial follows the same format as my other tutorials, and the idea is that after this tutorial is over, you should be able to use Gradle in real life software projects.

  • Nice format. It’s really helpful to those who just want a big picture of gradle without being overwhelmed by details. Keep it up sir.

    • Thank you for your kind words. I really appreciate them.

  • Nice Post. Could you please share list of Gradle Commands?

    • I am happy to hear that you liked this tutorial.

      Could you please share list of Gradle Commands?

      If you want to compile a Java project by using Gradle, you should read the second part of my Gradle tutorial. It describes how you can create a simple Java project and explains the basic tasks that can be invoked after you have applied the Gradle Java plugin to your build.

      Also, if you need to figure out the tasks of an existing Gradle project, you should run the command: gradle tasks.

      I hope that this answered to your question.

  • you have explain very well . Thanks a lot .

    • You are welcome!

  • I really appreciate the effort that u have put to explain, and it really helped me.

    • Thank you for your kind words. I really appreciate them!

  • Short and sweet… Thanks for sharing awesome blog post…

    • You are welcome. It is nice to hear that this blog post was useful to you.


Leave a Comment