Java Build Tools: Part 1 – An Introductory Crash Course to Getting Started with Maven, Gradle and Ant + Ivy
Chapter I: An introduction and [rather] short history of build tools
Build tools are an integral part of what makes our lives easier between checking code in and testing your product. Love them or hate them, they’re here to stay so let’s first take a look at what they are, how they emerged and why they are both hated and revered today.
What is a build tool and what does it do?
Let’s start at the beginning. What is a build tool? Well, as its name suggests, it is a tool for building – shocker! OK, that’s a bit too simple: build tools are primarily used to compile and construct some form of usable software image from your source code. This software image might be a web application, a desktop application, a library for other code bases to use or even a full product.
Build tools have evolved over the years, becoming progressively more sophisticated and feature rich. This provides developers with useful additions, such as the ability to manage your project dependencies as well as automate tasks beyond compiling and packaging. Typically, build tools require two major components: a build script and an executable, which processes the build script. Build scripts can be (and should be these days!) platform agnostic, eg. it may be executed on Windows, Linux or Mac at the same time.
We broke it down into this reasonable list of main tasks and requirements a good build tool should be good at:
- Incremental compilation
- Properly handling compilation and resource management tasks
- Handling different profiles (development vs. production)
- Adapting to changing product requirements
- And last but not least: designed to automate builds
Tools we’ll cover in this report: Maven, Gradle and Ant + Ivy
Although it’s not possible to give proper coverage to all the build tools in the world, we hope that by covering the top 3–Maven, Gradle and Ant + Ivy–in relative detail will be enough for most readers. If not, feel free to introduce us to some new technology!
Firstly, Apache Maven. Maven is a Yiddish word meaning accumulator of knowledge. It is currently the most popular (by number of users) build tool on the market today, and often the de facto first choice among Java developers. Originally, Maven was created in 2002 but really struck a chord with Java developers in 2005 when Maven 2 was released.
We’ll also look at the combination of Ant and Ivy in partnership. Both, projects from Apache, bring different things to the build tool table. Ant provides the capabilities to run specific tasks or targets, such as compile, test, build etc, whereas Ivy gives the dependency management required to enable larger more complex projects with dependency trees to be managed in a much easier way.
Lastly, but by no means least, we will also be looking at Gradle. As the newest build tool that we will focus on in our report (version 1 released in 2012), Gradle is a tool designed around multi-project environments. It takes a lot from what was learned from Maven and Ant, while daring to tread new ground, like choosing to use a Groovy style DSL rather than XML for its config scripts. Gradle’s plugins primarily focuses on Java, Groovy and Scala.
Other build tools which are worth mentioning and looking at include SBT, Tesla, Buildr, Tweaker, Leiningen and of course Make! However, one of these we feel like should have a bit of a call out going to talk about in more detail…