1

I am on my final year on CS, working on my first significant project, so I thought its about time to learn and use build tools.

I have read about Maven mainly and heard about Ant. I would like to know your opinion about which I should learn to use for a project that will be developed only by one person, keeping in mind the learning curve, and the functionality that will be useful in this case.

yannis
  • 39,547
  • 40
  • 183
  • 216
latusaki
  • 437
  • 1
  • 4
  • 12
  • Maven and Ant are both about build automation, but do follow quite different approaches (unfortunately I'm a little rusty on both). Since your question is essentially on which approach would better fit your project (and why), it's definitely on topic here, so I've edited out your ps. – yannis Dec 09 '11 at 01:28

3 Answers3

9

They both have their main strength and will both be sufficient to fill your needs. Here is my own little comparison with both hopefully will allow you to choose.

Maven

The more advanced of the two and certainly one of the most advanced build tool I have used. But to call it a built tool is not truly describing it as one of the most innovative feature of Maven is about dependency Management. In short it will handle all the mucking around with external libraries, it will download them for you it will validate that their dependencies are also resolved and downloaded, in short it will handle a lot of the greasy details of building a complex system.

Maven also relies heavily on conventions on how you layout your project's folders for source code, resources, tests etc. Follow these conversions and it magically just work (tm). Try to be smarter than them and it will give you pains beyond comprehension. I exaggerated a bit here, V3 has gotten a lot more friendly than the previous ones but it will leave you sometimes scratching your head.

Still these convention make it possible to create a project very quickly and with a few declarations in your pom.xml (the build entry point) you will be able to build your project, run all your tests and package a jar file just by issuing a single command line statement (mvn clean package). No scripting, no programming just follow convention.

Another side effect of these conventions is that all Maven projects are basically created the same so getting a new guy to join in or digging deeper in one dependency that is acting up is a breeze.

Magic is probably the worst aspect of working with maven. If you are a control freak Maven will often throw you off balance. But sticking to it and understanding the magic will richly reward you with overall greatly increased productivity.

Ant

Ant is more ancient than Maven and does not handle as much. Ant will have pre-packaged a lot of task that you must manually assemble into a build script. The script is a mix between declarative xml and scripting. the Ant scripting is actually Turing complete so you can do a lot with it but XML is not the best medium to write complex scripting logic.

Ant will leave you in control and will provide lots of canned stuff for you already. However this control comes at a cost and you will have to get the ground work and frame your build environment.

Ant also does not, at least not naturally, handle dependencies. to it it is just another classpath folder that you must populate manually. there are ways to handle this though through other systems such as Ivy.

Ant with Ivy will provide almost all the power of Maven but will leave you much more control over your process.

That said once the build framing is done Ant is pretty easy to use and if you structured your build.xml files right is pretty easy to expand and scale. frame your build wrong though and you find yourself having to re-write everything from scratch just to support that second project.

Best of both worlds

Go with Maven as it will demand just about the same amount of work to setup as a tool but will get you going much faster.

Do read the Maven book it has all you need to get started. If at some point you need more control you can check out the Maven Antrun plugin. It will allow you to execute arbitrary ant script while still have access to all the Maven environment and conventions. That said, most likely you will not need it. Personally I've been using Maven for 6 years and only once had to use it.

There are other build tools for Java but these two (along with Ivy to complement Ant) but I have not tried them so I cannot comment them here.

Newtopian
  • 7,201
  • 3
  • 35
  • 52
1

Maven and Ant have been very popular build/project management tools, but they are not going to be around forever. If you want to try something that is on the bleeding edge these days, check out Gradle.

Gradle gives you the best of both (Ant & Maven) worlds.

  • Dependency management out of the box (Ant does not have this without Ivy and it is a bit cumbersome to set up)
  • A re-configurable/extensible project lifecycle. (You have the lifecycle with Maven but it is hard to reconfigure it)
  • No more XML. (When you write gradle scripts, you program in an actual language (groovy))
  • Multi-project build capabilities (Easier to have smaller more focused modules and to glue them together)
  • Integration with both Ant and Maven

(Just to mention some... for more, check out their website)

It might still be a good idea for you to learn about Ant and Maven, just because most places still use one of these two tools, so you can use it as an experience builder.

c_maker
  • 8,250
  • 4
  • 35
  • 53
0

I would have a go at Maven. It is the most popular build tool used with Java these days. It seems like pretty much every Java framework and library you can think of is built using it which means (at least) two things:

  • Going forward it is most likely a more desirable skill to have than Ant.
  • The dependency management built into Maven (a feature that Ant does not have) can be used to effortlessly include all those 3rd party libraries and frameworks in your project.

It also uses good philosophies like 'convention over configuration' which encourages consistent project structures in all the projects that use it (so when you see a Maven project, you immediately know where most things should be) and that your build configurations are nice and small and maintainable.

Neither tool is particularly difficult to learn. Learning Maven is more about learning concepts whereas learning Ant is more about learning individual commands.

EDIT: This is a really good doco on Maven: http://www.sonatype.com/books/mvnref-book/reference/

Gyan aka Gary Buyn
  • 2,775
  • 19
  • 17