Thursday, July 12, 2007

Ant vs Maven

I've recently moved the build tool of a large multi-project system from Ant to Maven. I liked the concept of Maven, in particular, the ability to declare dependencies on third-party libraries and load them from a shared repository, the ability to work with a hierarchical project structure, and in general, a tool that makes common build tasks simple.

In the end, I'm not sure if a complex build environment can be neatly abstracted from lower level coding or whether Maven is just poorly implemented in parts.

Firstly, the dependency management feature has introduced as many problems as it has saved. I end up downloading more JAR files than I expected since the third party libraries I use have their dependencies which have their dependencies and so on. Some of the libraries in the public repositories don't seem to do a good job of keeping dependencies to a minimum required set. In addition, the same library will be downloaded multiple times as each dependent library specifies a difference version. So the reality is a great deal of time is required to specify exclusions and research the dependency trees of various libraries. Therefore, little time is saved compared with manually downloading only the necessary libraries.

Secondly, doing anything out of the ordinary quickly gets difficult and complex. For example, copying an artifact to a non-default location requires adding and configuring a plugin. Many complex tasks must resort to using the Maven Antrun plugin to run ant tasks (which defeats the purpose of moving from ant) or to writing your own plugin.

Thirdly, many of the plugins are poorly documented and implemented. For example, the Maven Archetype plugin used to create a project template uses Velocity to perform variable substitution in template files. However, if you want to use Velocity template files as part of the project template you can't.

The verdict is I'm sorry I spent a great deal of time moving to Maven. Maven is faster for straightforward projects with a standard compile, test, package and deploy lifecycle. But once you need to automate other tasks, such as generating Hibernate mapping files, or manage a large number of dependencies, Maven quickly starts to become an obstacle rather than an enabler.

No comments: