Book review: "Building and Testing with Gradle"
Gradle is a very flexible and powerful build tool, allowing an extremely concise build file for conventional projects and letting you do whatever crazy thing your project requires using a Groovy DSL. I’ve been following its development for the last two years, and I introduced it to replace a legacy Ant based build system at my work about a year ago.
As far as I know, Building and Testing with Gradle, written by Tim Berglund and Matthew McCullough and published by O’Reilly, is the first book published on this topic.
The first chapter will guide you through the installation process and the use of the Gradle from the command line. I’m not sure someone willing to use Gradle needs that kind of information. It will also show you the shorter build file possible for a Java project, containing only 18 non-whitespace characters: compare this with Maven…
The second chapter is were the serious stuff begins. It presents the basic unit of Gradle build files: tasks. The two lifecycle phases, configuration and execution, are explained. You’ll also learn how to use their rich API and how to simply write your own tasks. If you’re used to the complexity of Maven, be prepared for a shock as this is dead simple and way conciser.
The third chapter shows how Gradle can leverage your existing Ant files and custom tasks. This particularity of Gradle allows a step-by-step migration from Ant.
The fourth chapter compares Maven and Gradle. Gradle takes the best ideas from Maven (and others): convention over configuration, consistently named artifacts and a solid dependency management with the same central repositories. It drops what makes Maven so painful to use: tons of XML, a rigid lifecycle and more generally its lack of flexibility.
The fifth chapter is about testing. The integration of JUnit, TestNG, Spock, Geb and EasyB will be rapidly shown.
The sixth and last chapter is focused on multiproject (or multimodule) builds. Once again, the tremendous flexibility of Gradle makes it bend to your needs rather than imposing its standards on you.
This is a short book with fewer than a hundred pages, read in a couple of hours, and full of code samples. It is an introduction to Gradle, not a complete reference guide: it will show you the power and the simplicity of Gradle, and - I hope - will convince you to give Gradle a try.