This post originated from an RSS feed registered with Java Buzz
by dion.
Original Post: Why I like Maven: Commonality and Variability
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
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!