Jabbering Giraffe


After being a little bit ranty about cocoon yesterday, I thought I’d better take a closer look at Cocoon 2.2. But that means getting to know Maven first…

The premise of Maven is simple. Instead of having a scriptable build system (as with ant), the build system knows how to do things. And it does them in a standard fashion. You might call this convention over configuration. I like this idea, it simplifies things a lot.

To use Maven, you create a pom.xml (Project Object Model) file and then run mvn package. You should end up with a jar file for your project. This is a sample POM file:

    <description>My first Maven project???</description>

Ah, but how did I get this far? As it turns out, Maven has the equivalent of the rails command to generate new projects for you. Maven calls it an archetype. Here’s a simple example of generating a new project from an archetype from the tutorial:

  mvn archetype:create \
    -DarchetypeGroupId=org.apache.maven.archetypes \
    -DgroupId=com.mycompany.app \

Piece of cake, huh? And guess what? mvn --help gives no clue about any of that.

The second annoyance is quite how verbose Maven is. I know I’m an old-school Unix guy (silence is golden), but this is taking the piss:

  % mvn package
  [INFO] Scanning for projects...
  [INFO] ----------------------------------------------------------------------------
  [INFO] Building my-app
  [INFO]    task-segment: [package]
  [INFO] ----------------------------------------------------------------------------
  [INFO] [resources:resources]
  [INFO] Using default encoding to copy filtered resources.
  [INFO] [compiler:compile]
  [INFO] Compiling 1 source file to /Users/dom/work/my-app/target/classes
  [INFO] [resources:testResources]
  [INFO] Using default encoding to copy filtered resources.
  [INFO] [compiler:testCompile]
  [INFO] Compiling 1 source file to /Users/dom/work/my-app/target/test-classes
  [INFO] [surefire:test]
  [INFO] Surefire report directory: /Users/dom/work/my-app/target/surefire-reports

   T E S T S
  Running net.happygiraffe.app.AppTest
  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.164 sec

  Results :

  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

  [INFO] [jar:jar]
  [INFO] Building jar: /Users/dom/work/my-app/target/my-app-1.0-SNAPSHOT.jar
  [INFO] ------------------------------------------------------------------------
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 9 seconds
  [INFO] Finished at: Tue Apr 17 08:51:40 BST 2007
  [INFO] Final Memory: 5M/14M
  [INFO] ------------------------------------------------------------------------

What’s worse are the error messages. Check this out:

  % mvn pakage
  [INFO] Scanning for projects...
  [INFO] ------------------------------------------------------------------------
  [INFO] ------------------------------------------------------------------------
  [INFO] Invalid task 'pakage': you must specify a valid lifecycle phase, or a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal
  [INFO] ------------------------------------------------------------------------
  [INFO] For more information, run Maven with the -e switch
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: < 1 second
  [INFO] Finished at: Tue Apr 17 08:53:08 BST 2007
  [INFO] Final Memory: 1M/2M
  [INFO] ------------------------------------------------------------------------

So buried somewhere in there is the problem (“pakage” instead of “package”), but it doesn’t even warrant an error? Pretty unfriendly behaviour.

The third problem is shown up the first time you run a Maven command. I didn’t show it above because I’ve been playing with it already. But most of Maven’s behaviour is implemented as plugins. And these plugins are downloaded on first use. The Maven download itself is only about 1Mb.

Now, I don’t have a problem with plugins, or them being downloaded. But, for a fresh install, I would really rather be able to unpack and go. I don’t always have Internet access. On top of this, I have no idea about the provenance of the code that’s being downloaded. And the source code isn’t automatically brought along with it (unlike CPAN or rubygems). So you really have no idea what’s going on and you just have to trust that it’s doing the right thing. Trust is earned, though. I don’t trust Maven to do the right thing yet.

With all those complaints, I still think Maven is useful. The dependency management (ability to pull in dependent jars) is fantastic. The standardization of project layout is a boon. The ability to simply produce code quality reports is kind of handy. The Maven eclipse plugin is pretty reasonable. Indeed, the eclipse support for Maven itself (used to create the .project and .classpath files for Eclipse) is great.

But if Maven wants to see wider adoption, it really, really needs to spend some time working on the UI issues. They’re not easily dismissable just because this is a developer tool.

Anyway, after working my way through the tutorial I’m comfortable enough to start playing with cocoon 2.2 now.