Alex's Undercover Blog

Better Builds with Maven

Posted: 2007-03-12T06:23Z[UTC] by Alex

As a software developer I'm constantly looking for tools and techniques to make the development process easier. I used to use a strict command-line environment and XEmacs for my Java Development until I was introduced to Eclipse which is a very nice, extensible IDE for Java and other languages (though it does Java best). The fact that I can refactor code (rename a class for example), constantly build in the background to check for errors, handle version control and project dependencies all in one place was a God-send. There was still one glaring flaw, however. Ant builds, while flexible, can be a pain to setup, even with an IDE, and because there's no standard for how to setup builds (because it's so flexible) the setup process can tend to be a bit frustrating. This is where Maven comes in.

Maven is a Java tool who's mission is to standardize building a project and managing its dependencies. When creating a new project you create a simple XML document called a POM (Project Object Model) which describes the project as well as what its dependencies are. Maven defines a standard directory structure for creating projects. Because a standard is defined (though it can be overridden) there's no reading through complicated build.xml files to figure out what's going on or what targets you need to run in order to get the desired effect. This means that new developers to a project can get up to speed much faster. This also greatly simplifies the maintenance that needs to be done on the build setup of a project.

With Maven the days of storing a project's dependencies in a child lib/ directory are over. When you build a project Maven will automatically download all the necessary dependencies and install them in your local repository. The local repository is for all Maven projects to use so, for example, if you use JUnit for testing purposes Maven would download the appropriate version (whichever you define), store it and make it available for use with all projects. This means you don't have to store your binary dependencies in version control. Maven handles it all for you.

Maven doesn't stop there though. It can also handle generating documentation, building a website for your project and deploying your project to a shared repository for others to use and more. If that's not enough you can also integrate specialized Ant tasks into your Maven builds which will make the transition from Ant to Maven much more simple.

Having said all this wonderful stuff about Maven there is a reasonable learning curve, though it's not nearly as bad as Ant's. For assistance here are some helpful links to get started with:

Happy coding!

  • development
  • java
  • maven
  • undercover