Gradle in Action – Had enough of Maven and Ant? Try this powerful Java build tool – #programming #bookreview

Gradle in Action

Benjamin Muschko

(Manning, paperback)

Apache Maven and Apache Ant are perhaps the two best-known and most widely used Java build tools. But Gradle is gainmuschkoing users and aficionados ( if, indeed, there can be “fans” of software build tools). And this well-prepared new book likely will help Gradle achieve even wider acceptance and employment in the workplace.

“Gradle,” writes Benjamin Muschko, “is the next evolutionary step in JVM-based build tools. It draws on lessons learned from established tools like Ant and Maven and takes their best ideas to the next level. Following a build-by-convention approach, Gradle allows for declaratively modeling your problem domain using a powerful and expressive domain-specific language (DSL) implemented in Groovy instead of XML. Because Gradle is a JVM native, it allows you to write custom logic in the language you’re most comfortable with, be it Java or Groovy.”

Muschko has a strong bias toward Gradle, of course. He is a member of the Gradleware engineering team and has written several popular Gradle plugins.

Nonetheless, his well-written, 15-chapter, 456-page book makes a compelling case for Java developers to add Gradle to their build-tool cabinet and list of skills.

“Over the course of years,” Muschko contends, Maven and Ant “[have] significantly improved and extended their feature set. But even though both are highly popular and have become industry standards, they have one weak point: build logic has to be described in XML. XML is great for describing hierarchical data, but falls short on expressing program flow and conditional logic. As a build script grows in complexity, maintaining the build code becomes a nightmare.”

To use Gradle, you do have to learn parts of yet another programming language, Groovy. But, if you already know Java, you are much of the way there.  “The language [Groovy] integrates with existing Java classes and libraries, which makes it easy for Java developers to learn it.” Muschko stresses. “Not only does Groovy build upon the strengths of Java, it also provides powerful programming features inspired by those of Ruby, Python, and others. Groovy can be used as a scripting language without having to compile the code. Alternatively, Groovy code can be compiled to Java bytecode.” (Both approaches are used in the book.)

“Gradle’s core functionality is built with Java,” Muschko points out. “On top of this functionality sits a domain-specific language (DSL) written in the dynamic programming language Groovy. When writing a Gradle build script, you automatically use the language constructs exposed by this DSL to express the desired build instructions. Gradle build scripts are executable Groovy scripts, but they can’t be run by the Groovy runtime. When the need to implement custom logic arises, you can use Groovy’s language features to build out the desired functionality directly in the Gradle build script.”

Gradle in Action uses some Groovy in most of its code examples. But you are not expected to have experience with that language. Instead, Muschko gradually introduces Groovy and shows how it is used in the build processes, while keeping the book’s focus on Gradle and Gradle’s advantages over Maven and Ant (with Ivy). (You can run many of the book’s code examples from the Gradle command line and also, as I did, try out some of the Groovy code snippets using Groovy’s console. And Chapter 10 describes Gradle’s IDE plug-ins for Eclipse and NetBeans.)

“This book is primarily for developers and build automation engineers who want to implement a repeatable build that’s easy to read and extend,” Muschko says.

Muschko’s book is organized into three parts:

  • Part 1, Introducing Gradle
  • Part 2, Mastering the Fundamentals
  • Part 3, From Build to Deployment.

Part 1 includes an introduction to project automation and illustrates the differences in how builds are put together in Maven, Ant, and Gradle. It also shows how to write and execute a simple Gradle script, run Gradle on the command line, and build a Gradle project by example.

Part 2 delves into more advanced topics such as dependency management, testing an application with Gradle, extending a build with plugins, and other subjects, such as multiproject builds. It also digs deeper into testing, Gradle’s extension mechanism, and “how to translate existing build logic from one tool to another, identify integration points, and depict migration strategies.”

Part 3  emphasizes how to use Gradle in deployment. “In times of increased pressure to deliver software quickly and frequently,” Muschko writes, “automating the deployment and release process is extremely important. In part 3, you’ll learn how to use Gradle to its fullest in the context of continuous delivery.”

Meanwhile, Appendix A provides a closer look at how to use Gradle’s Command Line Interface, while Appendix B, titled “Groovy for Gradle users,” provides an introduction to what the author terms “Groovy’s most important language features,” with recommendations to help you learn more Groovy on your own. 

“For years, builds had the simple requirements of compiling and packaging software,” Muschko says. “But the landscape of modern software development has changed, and so have the needs for build automation. Today, projects involve large and diverse software stacks, incorporate multiple programming languages, and apply a broad spectrum of testing strategies. With the
rise of agile practices, builds have to support early integration of code as well as frequent and easy delivery to test and production environments. Established build tools continuously fall short in meeting these goals in a simple but customizable fashion.”

So, will it be Gradle to the rescue? In some settings, perhaps yes. In other environments, you may need to know how to use Maven, Ant and Gradle, plus some other build tools. And in still other work settings, the powers that be may insist on Maven or Ant or something else.

In any case, if you work with Java software builds, you may want to consider learning Gradle (and, by default, some Groovy, too). If so, give serious consideration to Benjamin Muschko’s excellent new how-to book.  In its foreword, Hans Dockter, the founder of Gradle and Gradleware, terms Gradle in Action “the authoritative guide.”

Si Dunn

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s