Friday, February 06, 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.

update:
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.

17 comments:

Jelmer said...

the coolest thing about maven is that it can be deleted

Anonymous said...

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

Steve Harris said...

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

Jean-Francois Poilpret said...

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;-)

Steve Harris said...

Really, cool, did not Know that, I'll test it out and then update the blog. I already had m2eclipse installed.

Steve Harris said...

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?

Jean-Francois Poilpret said...

Hi Steve,

what I say is that there are 2 breeds of plugins involved here:

- one is the maven plugin that will generate the eclipse project (to be imported into eclipse later on). You need this plugin to call "mvn eclipse:eclipse" (step 3), hence it has been installed during or prior to this step.
- the other one is an eclipse plugin to "call maven" from eclipse, you need to install it manually from within eclipse> Note that I don't use it personally because I always work with both eclipse and a shell (for launching mvn commands) started.

What you say in your step 4 is that you had to install the first kind of plugin (according to the link you provided) in order to have the functionality of the second kind of plugin (ease dealing with maven from eclipse). So I conclude the link you provided is incorrect. Actually this link should be the one provided in another comment (http://m2eclipse.codehaus.org/): that one IS an eclipse plugin to ease maven use FROM eclipse (not the opposite).

Hope I am clearer now;-)

Anonymous said...

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 http://m2eclipse.codehaus.org/, and possibly step 3 isn't necessary.

Steve Harris said...

Ah, Got it. Fixing it now. Thanks!

Unknown said...

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).

Mario Klaver said...

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.

Steve Harris said...

That's a good idea:
http://jira.terracotta.org/jira/browse/CDV-1128
Thanks

Eugene Kuleshov said...

Steve, if you have Maven integration for Eclipse (m2eclipse), then step 3) is redundant, so you can import your projects directly from local system, svn or from Maven repositories.

More over "mvn eclipse:m2eclipse" command is outdated and may not be compatible with latest m2eclipse configuration.

Unknown said...

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.

Anonymous said...

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.

Elvis from hell said...

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.

Anonymous said...

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