Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
A potentially complex build file demands an expressive format. XML was an easy choice for a build tool a decade ago, when it was a new technology, developers were enthusiastic about it, and no one yet knew the pain of reading it in large quantities. It seemed to be human-readable, and it was very easy to write code to parse it. However, a decade of experience has shown that large and complex XML files are only easy for machines to read, not for humans. Also, XML’s strictly hierarchical structure limits the expressiveness of the format. It’s easy to show nesting relationships in XML, but it’s hard to express program flow and data access the way most common programming language idioms express them. Ultimately, XML is the wrong format for a build file.
Gradle expresses its build files in Groovy. Groovy is a dynamic language of the JVM, similar in many respects to Java, but with some important differences. Every Gradle build file is an executable Groovy script. As a beginning Gradle user, you don’t even need to be aware that you’re writing Groovy code, but as your needs become more sophisticated, the power of the Groovy language may become very important. Unlike the build file formats of Ant and Maven, Gradle’s Groovy-based build files allow you to do general-purpose programming tasks in your build file. This relieves much of the frustration developers have faced in lacking control flow in Ant or being forced into plug-in development in Maven to accomplish nonstandard tasks.