Saturday, May 26, 2012

Maven or Ant?

Contrary to what @Joe Skora has said, with Maven 2 I have rarely needed to use ant in combination with Maven. Maven 1 was built on top of ant, so you often found yourself dropping down into ant related things. I rarely have, however, with Maven.
These are the reasons I advocate Maven:
  • Repeatable builds / Dependency Management. All it takes is a check out of your source and, if necessary, a Maven configuration file, and you can issue one command and all of the dependencies for your project will be downloaded and then the project will be built. No checking of binary jars into your source control, or manually copying things, or whatever. Also, it handles transitive dependencies. If you depend directly on one library, you don't have to list its dependencies as well. Maven automatically figures that out for you.
  • Versioned artifacts This is an extension of the above point. Any given Maven project is required to have a version number. When you deploy built resources to your internal Maven repositories, it is easy to point to any given version. After getting used to this method of development, it doesn't make sense to me any longer to not have versions of both the built artifacts and its dependencies when doing development.
  • Convention and configuration over scripting. Maven has set conventions for project layout. It constructs classpaths based upon your declared dependencies and their transitive dependencies. With ant, you have to explicitly write out XML "code" for the steps to compile, to construct jars, to set up your classpaths, etc. Maven is much more declarative.
  • IDEs Yes, many ides have Ant integration or are based upon ant. Yet, I find that many people who use ant built scripts tend to check in IDE project files (.project for Eclipse, for example) into source control. This is often bad because of pathnames and so forth. With Maven, out of the box you can generate project files for Eclipse and IDEA, and other IDE's like Netbeans can simply open existing Maven projects. No need to check configuration files into source control.
Those are my main reasons for advocating Maven. However, as others have noted, it is far from perfect:
  • The documentation is lacking in places.
  • Sometimes you have to do silly things to work around bugs in the dependency calculation mechanism.
  • It can be slow at times (though I hear this is being worked on).
The declarative dependency management and version artifacts alone have got me sold on Maven.

No comments:

Post a Comment