Ri18n: i18n for Ruby Facelets: JSF down right…. but what do you give up?
Jul 27

Why I like Maven: Commonality and Variability

Builds, Tech Add comments

I realised another reason why I enjoy using Maven the other day.

Let’s start from the beginning….

I often have my build self-contained, so I can run goals/targets to do everything:

% maven/ant dbstart

% maven/ant tomcat-start

% maven/ant redeploy

This way all of the properties are setup correctly for the given project. No futzing around making changes.

Over time we find useful, generic (common) goals that we reuse on each project.

I see this happen in two ways in the ant world (not that it has to be like this!):

  • Don’t even reuse the targets a lot
  • Copy ‘n paste reuse: Oh foo was useful in the last project lets copy it in here

Before you look around there are 4 versions of dbstart in 4 different projects.

Now, what if you are a good boy, and you abstract out the commonality into a seperate build.xml and you just include that, as you can now in ant 1.6?

You end up with scripts such as this jsp precompile that projects use (e.g. AppFuse).

What if fhanik changes his script? Bah, whatever.

Here’s where Maven comes in

I have created plugins such as maven-db-plugin, which abstract all of the database stuff into a nice module. Now I have db:start, db:stop, db:dump, db:populate, etc etc in one nice module.

When I start a new project, I simply declare this dependency and I am done. The variability comes in the various maven properties that I can set in my project (e.g. using mysql, the jdbc driver, the user/pass, etc). Maven 2 has even nice auto-plugin installation which makes this even cleaner!

The nice thing about this is that development on making the db plugin is seperate from the project. If I release a new version of the plugin that fixes a bug, or adds a feature, I have the option to use that version in any project with a simple dependency change.

I end up with a lot less dead code, and my build related files stay nice and small, as all of the commonality is elsewhere.

This may sound like a very simple thing, but I sure appreciate it!

7 Responses to “Why I like Maven: Commonality and Variability”

  1. Anonymous Says:

    Great. I did this 5 years ago with Ant and I can change database on the fly and it will pickup the appropriate sql files (postgres, mysql, oracle, …) to create db and populate.

    It has been reused for the last 5 years in all my projects with improved flexibility and simplicity and the build configuration is centralized and versioned. It has been used successfully (and still is) within a commercial product made of 700KSLOC, 40 modules and over 70 dependencies (opensource or commercial) with a mix of C, C++ and Java building on 3 Linux, Solaris and Windows.

    Oh, and the Ant build file for a typical module is 6 lines.

    Any other reason why Maven is useful ?

  2. Charles Miller Says:

    I’d like to nominate the comment above me for the “Gratuitous Dick-Waving Award” of July 2005.

  3. Dion Says:

    Anony Mouse -

    I don’t think the point was that maven is the only tool in which you could do database stuff, or that you can’t do custom things to modularise.

    I just think maven is good at doing it :)

    And, although your home grown thing could be cool, I don’t get much benefit from it. With maven, when some nice person updates the FOO plugin, I DO benefit from it.

    Cheers,

    Dion

  4. Anonymous Says:

    NIY syndrom… oh well…

  5. dion Says:

    We also have a ‘db’ plugin.

    Maybe we should all work on a common plugin.

  6. Jason Carreira Says:

    Well, I won’t gratuitously wave any appendages, but it’s possible (and not that hard) to do the same with Ant…. And Ivy’s dependency resolution is better than Maven’s.

    How’s those Jelly scripts treating you? How much fun is it when you want to do it slightly differently from the way the plugin writer wanted you to do it?

  7. Big Stu Says:

    This thread is full of win.

    Let’s all circle up and show each other our ‘db plugins’.

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: What is the number before 3? (just put in the digit)