Thursday, 27 January 2011

Build process

Why Maven ?

 I had to decide which build system to use, Ant or Maven. We use Ant at work, and it's a fairly sophisticated script, using a lot of inheritance and overriding to build the project. I've written Ant scripts before, and to be honest, it's dull and a bit of a ballache. So I decided to try Maven as :
1. It's new
2. It'll save time on the build dependencies
3. It integrates with Eclipse through the m2Eclipse plug in.

I figured once it was up and running, it'd save time, and it's a useful tool to have.

Maven documentation

The Maven documentation isn't good, it reads like one of those guides that makes more sense after you've been using it a while. I've hunted through a few blogs, some of which are good, but that's inevitably fragmented. I'm using Apache Maven 2 Effective Implementation (by Ching and Porter) as my main reference, and it's proving reasonably useful : better than the initial review on Amazon suggests anyway.

What to use as a Maven repository ?

Maven generally recommends using a proxy repository, and after checking a good article on theserverside.com and the Maven book, decided to check out Archiva . It's turned out to be a good find, being very easy to set up and use, with decent documentation. Again, follow the wizards, there isn't much more to it.

Multi module Maven

So I started to generate a multi module Maven project. It turned out to be simple using the mvn:generate task, the only thing I'd have liked would be some guide to the archetypes available. For a newbie, the list is large and it's not clear what's going to be the best to use.
I hit one massive problem during the build, where the first module would build, but the second module couldn't find the first build's arrtifact, stating the jar could not be found in the local repository. Close review of the logs showed the first module was publishing to the local repository, and I could see it there.
The problem ? The dependency tag in each module's pom.xml :

      <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>maven-importer</artifactId>
            <version>${project.groupId}</version>
        </dependency>
      </dependencies>

It should have read :

      <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>maven-importer</artifactId>
            <version>${project.version}</version>
        </dependency>
      </dependencies>

Which drives home the lesson I find most days : it's almost always something simple.

Still, I now have a working Maven build system, and a local archive.

No comments:

Post a Comment