Alex's Personal Blog

News and updates for friends and family

Articles tagged with development

Better Builds with Maven [DRAFT]

Posted: Sun, 11 Mar 2007 by

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: The Official Apache Maven Site Maven in 5 Minutes - A great place to start! Maven Getting Started Guide - Once you've gone through the 5 Minute guide above this is a nice, more in-depth tutorial. Better Builds with Maven - Free online book that is a great introduction and also goes into quite a bit of depth. Proximity - For those that would like to host their own Maven repositories and Proxy external repositories this a very easy setup tool to accomplish just that.Happy coding!

Updated: 2012-02-24 11:34:25 -0800