The T-Files


Thu, 15 Nov 2007

Maven

I started using Apache Maven and am really impressed by it. At first I was suspicious as to why we need another build system when we already have Apache Ant, but as it turns out Maven is doing much, much more than Ant, and is also easier to use. No wonder that basically all popular Java (it does seem to be limited to the Java world) projects are using it now.

First of all, it has a starter command that generates the project definition XML files, which defines what kind of project you have and how it has to be built. With Ant, you have to manually create a build.xml, which requires you to get down and study a little first. Plus, an initial build.xml probably does not do very much, whereas the initial pom.xml can even create a nice looking web presence.

Secondly, Maven seems to believe in Convention over Configuration. There are sensible defaults for everything, so if you adhere to established directory layouts and such, you can get results without any fiddling of parameters. A good example are the various reporting plugins, that create JavaDoc, or coverage reports, or dependency listings. Just drop in the plugin and without the need to specify source or output directories, or even to activate the new build step, you get the extra side-menu items in your report page.

Thirdly, and probably most importantly, Maven takes care of dependencies for both your project and itself. It automatically locates, downloads and installs all those extra JAR files, and makes sure the versions match up. If it is not already bundled with your OS (comes with Leopard for example), then installing Maven could be the last Java-related download you need to do yourself. When I decided I wanted Cobertura coverage reports yesterday, it was just a matter of adding two lines of code to pom.xml. Maven immediately downloaded the Cobertura plugin for itself, plus all required libraries. I remember it being much more work when I integrated Cobertura in our Ant build chain. The same goes for the dependencies of the project that is being built. Need Hsqldb for some junit testing? Just add it as a Maven dependency (using a convenient package name search dialog in Eclipse), and that's it. No need anymore to either put big third-party JAR files in your own project's version control system or have all developers find and install them manually.