Ant, Gradle and Maven - comparison - checking build prerequisites

So you decided to check some build prerequisites before doing any real job. You want to check if proper Java version is installed, if some configuration files are available etc.

I'll show you how you can do this using Ant, Gradle and Maven.

Please notice, that these code snippets are not equivalent. They are here only to illustrate how you can achieve similar effect using each of aforementioned tools.

So, let the code speak!


This snippet of code is taken from TestNG's build script (slightly changed).

<target name="validate">
  <condition property="requiredJavaVersion">
      <equals arg1="${}" arg2="1.3"/>
  <fail unless="requiredJavaVersion"
        message="Java version 1.3 required."/>
  • this way of doing "if" seems very unnatural,
  • too verbose,
  • not so easy to customize - in "then clause" you can do only what Ant tasks allow you to do (the good thing is, there are many Ant tasks available),
  • you need to know a lot about Ant and API of Ant tasks - condition, fail, ${}.


task validate {
        if (!['1.3', '1.4'].contains(System.getProperty('java.version'))) {
                println "ERROR Java 1.3 or 1.4 required !
                   (found Java ${System.getProperty('java.version')})"
  • very straightforward and easy to understand,
  • no restriction on what you can do in "then clause",
  • you need to know Java or Groovy,
  • no standard way of expressing such build requirement, so the code you come up with might be very different from what your next-desk-colleague came up with.


This snippet of code is taken from maven-enforce-plugin usage (slightly changed).

  • can do easily only what plugin authors predicted,
  • adding custom behavior is possible, but cumbersome (take a look here),
  • unnecessary verbose (goals, execution, id) for such a simple task,
  • this is a standard way of doing this kind of task with Maven,
  • you need to know such plugin exists (many Maven users don't - believe me).


This simple example shows what is the difference between XML based tools like Ant and Maven, and DSL (Groovy) based Gradle. First two are way too verbose and limit you only to things that were planned by tool author. This might be enough for simple cases, but will pinch in real-world development. Adding custom behavior will cost you a lot of effort.

Gradle allows you to do whatever you want, not limiting you with only a set of beforehand prepared choices. It allows to write more explicit, more verbose code. And I like it a lot.


This used to be my blog. I moved to long time ago.


Please comment using