Home > Articles > Web Development

Introduction to Gradle: A Modern Build System

  • Print
  • + Share This
James L. Williams, author of Learning HTML5 Game Programming: A Hands-on Guide to Building Online Games Using Canvas, SVG, and WebGL, shows how to modernize your Java (and JVM language) project builds using Gradle and make them more manageable, doing more by writing less XML.
Like this article? We recommend

I was once told, "Show me a developer who likes Ant or Maven, and surely he is one who hasn't used them long enough." More than a decade old, they are beginning to show their age.

Gradle is a build automation tool that integrates and improves Ant and Maven fundamentals. Instead of clunky XML files as in an Ant project, it uses the Groovy programming language to script all parts of the software development life cycle. It can leverage Maven conventions for familiarity while making it easy to customize to the needs of your project. Users are able to add, extend, and override tasks and plugins to create new functionality. Though Gradle is primarily used for Java, Grails, and Android projects, there are community plugins for building C++ and Mac apps as well as generating Linux packages.

In this article, you learn how to build, manage, and package projects with Gradle.

Why Use Gradle Versus Maven or Ant?

In addition to a long and clunky XML file, there is no standard format for an Ant project. Unless your company has code guidelines, each project’s structure might be unique. Much of the XML in the build.xml file is telling Ant where to find the files to compile and the project’s dependencies. Having to write and manage all this XML can be tedious.

Maven also uses XML files to run a build, but has a very different philosophical view than Ant. As opposed to a Wild West mentality when it comes to project structure, Maven has a standard way to structure your projects. We can see that basic structure listed in the following table:




File describing how to build the project.


Source code for the project.


Resources needed by the project build.


Source code for the project's test.


Resources needed by the test suite.

The benefit of this is once you learn the structure of a standard project, you know the structure of all Maven projects. Another improvement over Ant is in the area of dependency management. Maven uses collections of libraries called repositories that are organized by project and version number. The most commonly used repository, or repo for short, is Maven Central. When a project is run for the first time, the dependency JARs are downloaded from the repos listed in the project's POM (Project Object Model) XML file. It's also possible to have many local or remote repos. Maven also has a plugin system for extending functionality. Here is a sample pom.xml file:

[Sample pom.xml file]
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  <name>Mirah Shared</name>
  <description>The Mirah Programming Language</description>
    <system>Github issues</system>
      <name>Apache License, Version 2</name>
      <name>Charles Nutter</name>
    <!-- TODO: Add other developers -->

Gradle is somewhat of an evolution of Ant and Maven. An idiomatic Gradle project shares the same format as a Maven project. Gradle can make use of Maven repositories and, as opposed to boatloads of XML, it uses a Groovy DSL (Domain Specific Language) to define tasks and run builds.

  • + Share This
  • 🔖 Save To Your Account