Friday, February 6, 2009

Maven Is Cooler than you think...

I'm sure I'm not the only one who has heard people curse Maven. But Maven is cooler than you think. Back in the day when I wanted to start a project I always had to get a whole bunch of gunk setup before I even wrote a line of code. Especially when trying a new framework or tool. Today I was whipping up a new project for a simple micro-benchmark on some Terracotta stuff and it reminded me why Maven really can be quite awesome. It took me 10 minutes and about 7 steps. The next time around I won't need to do the installs and then it's 4 steps.

These were the steps I took to get started:

1) Install Maven 

2) Used the Pojo Archetype to create the build and test environment for my project.
- Creates a Mavenized directory structure ready for build, test, run etc. Hooks up to Terracotta maven plugin as well.
- make sure you replace the group id and project id in the command line.

updated - with the latest eclipse plugin this is unnecessary
X 3) In my new project directory type: "mvn eclispe:m2eclipse"
- This takes your Maven project and readies it for eclipse

4) Install the Maven Eclipse Plugin (I already had eclipse installed)
- Makes dealing with Maven from eclipse much easier

- Makes dealing with Terracotta from eclipse much easier

6) File-> Import-> Maven projects and import your project into eclipse
- Loads up the project directory created from the archetype into Eclipse
7) Select the project and hit Terracotta->Add Terracotta Nature

What you end up with here is a complete project setup ready to be built and tested from both Eclipse and the command line using Maven.

Literally took me about 10 minutes to get started. Notice what you didn't have to do.

1) Didn't have to build a pom.xml or other kind of build file
2) Didn't have to download or install Terracotta or any of it's pieces
3) Didn't have to think about your directory structures, where you want to put your tests, how you want to run those tests
4) Didn't have to figure out how to do all this stuff in Eclipse or the commandline

Sure, Maven can be challenging at times, but in cases like this, when the vendors have things setup for you, it can be a huge time saver.

Looks like we've reduced the number of steps to 6 the first time and 3 after that. If we take the guy's idea about auto-applying the Terracotta Nature in archetype we could reduce it to 5 and 2.


  1. the coolest thing about maven is that it can be deleted

  2. You could also use eclipse:m2eclipse if you use the codehaus m2eclipse plugin (, much neater from my point of view as all your dependencies are grouped together.

  3. I do use that plugin. Could you talk a little more about the differences between eclipse:eclipse and eclipse:m2eclipse

  4. Link is step 4 is wrong (or step 4 itself is wrong).
    The link points to the Maven plugin for Eclipse (which was already automatically downloaded in step 3), not to the Eclipse plugin for Maven;-)

  5. I'm probably just misunderstanding you. I uninstalled the maven plugin. Ran mvn eclipse:eclipse but the maven plugin wasn't reinstalled (which in hind sight is of course true because how would it know which install of eclipse to put it in from there). Are you saying it's just downloaded somewhere and I would need to install it myself?

  6. In step 3 you run, mvn eclipse:eclipse, which is the Eclipse plugin for Maven (and will create the Eclipse .project files).

    M2Eclipse is the Maven plugin for Eclipse (which allowed you to import a Maven project in step 6 - I think this might create a new Eclipse .project file also)...

    so I think step 4 should point to, and possibly step 3 isn't necessary.

  7. Ah, Got it. Fixing it now. Thanks!

  8. mvn idea:idea will generate a project for IntelliJ, too, although the format it generates seems to be a bit outdates (IntelliJ 7.0.5 asks to update the project when you first load one generated by maven).

  9. Yes, maven is great (sometimes). You could eliminate step 7 if the archetype added this nature automatically (or configure the maven-eclipse-plugin in your pom.xml to add project nature org.terracotta.dso.ProjectNature). This way eclipse:eclipse will add the nature automatically.

  10. That's a good idea:

  11. To love maven is to hate maven. Maven makes my days programming much easier, I would never wish to work without it. Getting to this point has been 5 years of pure hell though, and everything negative ever said about Maven is true and more. I currently use the MyEclipse version, but just because of laziness.

  12. Maven is terrible. I wasted a lot of time becoming familiar with it. It has some great ideas but is much too unflexible.

    If your build process has any non-standard aspects, then don't go there.

    POM and dependency declarations are unnecessarily complicated.

    There are better alteratives, for example Ant together wity Ivy.

  13. Maybe it's not maven, that sucks, but its integration does. Using it with Eclipse (or even rcp) is a PITA.
    Ivy? The tool support is even worse.

  14. Anyone saying Maven is inflexible simply hasn't bothered using it properly. Nobody seems to see the value of rescinding some tiny modicum of "control" (read: "tiresome effort") to the tool, in exchange for a vastly simplified process