Introduction to Gradle

Basic introduction about Gradle

Build automation?

Build automation is the act of scripting or automating a wide variety of tasks that software developers do in their day-to-day activities including things like:

  • compiling computer source code into binary code
  • packaging binary code
  • running automated tests
  • deploying to production systems
  • creating documentation and/or release notes


  • Gradle is a build automation tool that combines Ant's power and flexibility with Maven's build life cycle and dependency management conventions into a more effective way to build.
  • Gradle has it's own domain-specific language (DSL) based on Groovy instead of the more traditional XML form of declaring the project configuration.
  • Google adopted Gradle as the default build tool for the Android OS. 

Why Gradle? (Gradle v/s Maven v/s Ant)

Build automation tool are consists of two main parts: configuration and build. Configuration is static information about the build such as build scripts and build is dynamic part which actual action happens. * Gradle uses Groovy DSL for it's configuration and Groovy language for customizing it's build. * Maven is focused on configuration, hard to customize. * Ant is focused on build, hard to configure.

Gradle build scripts tend to be much shorter and clearer than those written for Maven or Ant.

  • Gradle (build.gradle)

    // build.gradle
    apply plugin: 'java'
    apply plugin: 'checkstyle'
    apply plugin: 'findbugs'
    apply plugin: 'pmd'
    version = '1.0'
    repositories {
    dependencies {
       testCompile group: 'junit', name: 'junit', version: '4.11'
       testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
  • Maven (pom.xml)

    <project xmlns=""
  • Ant (build.xml) with Ivy (ivy.xml)

    <ivy-module version="2.0">
      <info organisation="org.apache" module="java-build-tools"/>
         <dependency org="junit" name="junit" rev="4.11"/>
         <dependency org="org.hamcrest" name="hamcrest-all" rev="1.3"/>
    <project xmlns:ivy="antlib:org.apache.ivy.ant" name="java-build-tools" default="jar">
      <property name="src.dir" value="src"/>
      <property name="build.dir" value="build"/>
      <property name="classes.dir" value="${build.dir}/classes"/>
      <property name="jar.dir" value="${build.dir}/jar"/>
      <property name="lib.dir" value="lib" />
      <path id="">
         <fileset dir="${lib.dir}" />
      <target name="resolve">
         <ivy:retrieve />
      <target name="clean">
         <delete dir="${build.dir}"/>
      <target name="compile" depends="resolve">
         <mkdir dir="${classes.dir}"/>
         <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref=""/>
      <target name="jar" depends="compile">
         <mkdir dir="${jar.dir}"/>
         <jar destfile="${jar.dir}/${}.jar" basedir="${classes.dir}"/>

Gradle's compelling features

  • Expensive build language and deep API
  • Gradle is Groovy
  • Flexible conventions
  • Robust and powerful dependency management
  • Scalable builds
  • Effortless extendibility
  • Integration with other build tool
  • Community-driven and company-backend

How to install Gradle?

  • Gradle Installation
    1. Download 'Complete distribution' or 'Binary only distribution' from Gradle Downloads and unpack it.
    2. Create an environment variable GRADLEHOME where your 'gradle-x.x' is located.
    3. Add GRADLEHOME/bin to your PATH environment variable.
    4. Verify if Gradle set up properly with simple command gradle -v.

Gradle is shipped in Android Studio. No external installation is required if you are using Android Studio.


It's hard to discuss Gradle without Groovy language. Groovy is object-oriented programming language and also is a dynamic language and scripting language for JAVA platform. Gradle choose Groovy for it's language because of two main reasons: * The advantages of an internal DSL * Groovy is similar with JAVA * Highest transparency and lowest learning curve especially for developers who are familiar with JAVA

Gradle Wrapper?

Gradle Wrapper is the preferred way of starting a Gradle build. The wrapper is a batch script on Windows, and a shell script for other operating systems. When you start a Gradle build via the wrapper, Gradle will be automatically downloaded and used to run the build.


Name     : Leonardo Taehwan Kim
Email    :
Website  :