Maven IDE Support

My current project is using Maven for a build too (instead of the “standard” of Ant) and I’ve been very pleased with it so far.

I was initially concerned about how much support there was in the two IDEs I’m currently using (Eclipse and IntelliJ IDEA) for Maven. Fortunately they both have very good support (though… not quite perfect yet).

Both IDEs handle managing dependencies through Maven very well. This is probably the most important feature. You’ll never have to go through the hassle of setting up your dependencies within the build script and your IDE. Its defined once only!

Beyond that, both IDEs take slightly different approaches to Maven support.

In Eclipse, the Maven support comes via a 3rd-party plug-in you need to install (isn’t everything an Eclipse plug-in? :-)). The m2eclipse plugin provides a custom editor for managing the Maven POM file. Though I prefer to edit the XML directly I’m sure some will find the custom editor useful when editing their POMs. However, the most valuable part of editor (that IDEA has no counterpart for) is the Dependency Graph. m2eclipse will display a nice “visio-like” display of all the dependencies in your project with arrows indicating the direction of the dependencies. Its an excellent way to see what JARs you’re including in your project and why. I can’t emphasize the value of this feature enough (Here’s a simple example of it). Also, you can find a good overview of m2eclipse here.

What you really need to know is that using m2eclipse on your project tightly integrates Maven with Eclipse. Maven’s POM is the “source of truth” for your project. In other words, your POM is your project file. In fact, I’d recommend that the Eclipse .classpath (and maybe even the .project file) not be checked into a source code control system. Its replaced every time you make a change to your POM. This is important on my current project where I have several different profiles for running on different application servers and/or running with all local or shared resources. All I do is change my active profile and my source folders will be reset accordingly (picking up the correct *.properties files, Spring configuration files, etc).

Furthermore, (its not well documented, but…) m2eclipse will create source files for all your “resource” folders, but… it will ignore all the contents in them!. Instead, it invokes Maven’s “process-resources” lifecycle goal whenever you do a clean build or modify a resource. Your Eclipse build will always need to invoke some Maven goal to get your resources copied to the output directly (see this posting).

The downside of m2eclipse is that running Maven, changing the profile and other options are buried deep in the Eclipse Preferences and Project Properties screens. Toggling between profiles (which is something I need to do semi-frequently) is a pain. Furthermore, running specific goals needs to be managed through the “Run Configuration” and “Run History” screens.

Changing profiles and running goals is pain partially because IntelliJ’s IDEA does this so well. IDEA gives you a nice pane (tool window?) where you can enable/disable any profile detected in the project (via a list of profile checkboxes) and select/run any goal or task in the project. Its really handy. Also, IDEA’s POM editor is excellent. It doesn’t provide a fancy UI like Eclipse, but the POM XML editor is very smart (in keeping with IDEA’s general philosophy of “smart” text editors over UIs). But, where IDEA makes changing profiles really easy, it doesn’t actually support them that well. After reporting it as a bug to JetBrains, its obvious from their response that they have a different approach.

As I said before, both IDEs use Maven’s dependency listing as the source for your project’s classpath. However, where m2eclipse/eclipse treats the entire POM as the definition for the IDEs project, IDEA considers its project files as the main “source of truth”. IDEAs perspective is to import a POMs settings into the IDEA project.

With profiles, this becomes important. In Eclipse, when you change profiles the project gets “reset” to match the profile. But in IntelliJ, you “re-import” the project and IDEA will only add any new source folders and leave any existing ones (that are now invalid for the profile) still in place! Since JetBrains views the IDEA project as the master, they don’t know where the folders not in the current profile are there because of a previous profile or because you customized the project yourself. This makes dealing with profiles a pain because you constantly have to go into your project’s settings and correct the source folders to match the profile. This is compounded by the fact that IDEA assumes to own the output directories and doesn’t always detect that Maven has made changes to resource files. Depending on the situation, IDEA can get out of synch with the files underneath.

Neither the deficiencies in m2eclipse or IDEA is enough to really get in the way. I just really want to be able to have my cake and eat it too! If IDEA would treat the POM as the “single source of truth” for the project and have a Dependency Graph view I’d be thrilled! If m2eclipse would provide a “Maven View” similar to the “Ant View” Eclipse already has that included the profile switching, again I’d be happy as a clam. However, as it stands, no matter which IDE I use for Maven, I feel I’m missing something…

5 thoughts on “Maven IDE Support”

  1. If you prefer to use raw XML editor for editing pom you’ll find it convenient that dependency and other Maven code assists works in Eclipse XML editor when you editor pom.xml, just open it with XML editor or set that editor as default for these files.

    In regards some not well documented features in m2eclipse, please help us to expand the documentation. It is all on the wiki and editable by anyone, you just need to create an account there and you should be able to contribute your edits.


  2. Would be interesting to see a comparison including NetBeans 6.5. They also take the policy that the maven pom is the project descriptor, even more so than Eclipse as there’s no import set, you just open any directory containing a pom and it is treated as a project.

    The thing that might interest you more is that support for maven profiles is excellent. In the context menu for a project there is a Profiles submenu where you can select currently active profiles, these selected profiles are then used for any operations you perform on the project (build, test, run). If you find yourself running one operation regularly with a specific profile then you can also set up a “custom” run execution that becomes available on the context menu of the project.

    Dependency graphing isn’t quite as good as eclipse but it’s not usually a problem to see what’s being used, direct dependencies are also rendered differently from those that come as transient depenedencies.

    1. Interesting! I didn’t realize that NetBeans had Maven support. I knew that NetBeans did something similar with Ant files which I thought was pretty slick, but… I didn’t know Maven was supported too. I’ve heard quite a few people lately talking about NetBeans. Perhaps I should give it another look (though… I’ve recently become a big IDEA fan :-) )

  3. Personally, I use m2eclipse as the pom editor/’source of truth’ (especially handy when you have developers on different platforms, where a checked in .project/.classpath can be a source of fail).

    I still mostly run my builds from the command line, though. All the various profile activations I need are in my history, and tcsh’s smart completion makes puts any build only a few keystrokes away.

    I generally run the same couple of build commands 95% of the time, so kicking this off from is dead easy.

Leave a Reply

Your email address will not be published. Required fields are marked *