[CSS 2006] Using Maven 2 to get control over your Development Process

This afternoon I attended Hermod Opstvedt's talk on Using Maven 2 to get control over your Development Process. Most of it was review for me, but I took some notes anyway. About halfway through, I quit taking notes and just listened. The most interesting part for me was seeing how the Maven Embedder works. Since Maven doesn't currently allow you to create archetypes from existing projects the embedder seems like a good workaround. I'd rather code in Java rather than XML any day.

Near the end, Hermod tried to show us how you can easily create an Ant-based Mojo (Maven plugin), but his demo bombed thanks to an invalid pom in one of the plugin snapshots. Made Maven look pretty bad IMO - but snapshots always mess things up. ;-) The room was packed. Here's my notes:

What is Maven?
It's a kind of project management tool. It focuses on standards and best practices, uses convention over configuration, shared language for build management, repeatable robust builds and acts as a central point in the Project Object Model (POM).

Maven History
Maven is a result of trying to make several Apache Software Foundation (ASF) project work in the same predictable way. Offshoot of the Turbine project and started by Jason van Zyl.

Objectives
Creates a common and understandable build infrastructure. If you know Maven, moving from one project to the next means you can focus on the problem at hand and not spend time trying to figure out the build system.

Common problems in a project: Traditionally, the larger the project, the more complex and build system becomes. Very often the build system is copied form a previous project that the senior developers participate in. Setting up an initial project through copy and past obviously can lead to interesting issues. Versioning of a project often becomes a nightmare if a strict regime of code management is not introduced. Documentation process is often "put off until later". Testing infrastructure is generally mediocre at best.

Maven solves these problems by introducing common build logic and uses a standard naming convention. There is also a single output from a single Maven project (often a contentious issue).

The Maven standard build lifecycle provides a lifecycle to hook into to perform custom logic with plugins.

Archetypes
What is an archetype? It's a template of a project which is combined with some user input to produce a working Maven project that has been tailored to your requirements. It's used to initialize a new project of a particular kind. To use the archetype plugin, it's as simple as running:
mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp
For more information, see Maven's Guide to Webapps. Archetypes are very dumb for the most part - they're just a flat directory structure with files in it. However, if you want to create complex archetypes that execute something, it can't be done using the regular way. The solution is:
  1. Start out by creating an archetype for your standard structure
  2. Then in the pom for the project, add an <scm> section that will point to where your code is stored.
  3. Run "mvn archetype:create".
  4. Change to the root of your newly created project and run "mvn scm:update".
An alternative to all this is to create an Ant-based mojo. A Mojo is a Maven plugin that executes some code at a given lifecycle. It can run Java code, Ant scripts and more. the reason for using an Ant based mojo is that to be able to run more than one task in a mojo, we need to us what is known as the Maven Embedder.

Posted in Java at Oct 24 2006, 03:53:43 PM MDT 2 Comments
Comments:

Thanks Matt!

Posted by Mick Huisking on October 24, 2006 at 04:54 PM MDT #

Matt, thanks for that quick "However, if you want to create complex archetypes that execute something, it can't be done using the regular way. The solution is:" line. I started to get deep in to maven but never got to working with the scm part. i was turned off by the directory structure i thought i would have to live with of : my-app/trunk/my-app/src, my-app/tags/my-app, etc. is this still true when you use the scm plugins?

Posted by 198.45.18.28 on October 25, 2006 at 07:48 AM MDT #

Post a Comment:
Comments are closed for this entry.