14

With the maven-eclipse-plugin, using mvn eclipse:eclipse, you can specifiy eclipse project natures and builders that will automatically be added to the eclipse project.

Earlier versions of m2eclipse used the configuration block of the maven-eclipse-plugin and also let you activate natures and builders using the same mechanisms. This seems to no longer be the case because a) I can't find any reference to maven-eclipse-plugin in the m2eclipse sources and b) it just doesn't work :-)

So this is my question: is there any way to configure the eclipse project generated by m2eclipse from the pom.xml? Specifically: project builders and natures, but I'd be interested in other options as well.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588

3 Answers3

9

The following thread summarizes almost everything. First, it explains that m2eclipse doesn't and won't support anything from the Maven Eclipse Plugin anymore because:

  1. Sonatype doesn't maintain it.
  2. It causes them too much troubles.

Second, it states that the m2eclipse way to handle additional project natures and builders is to write project configurators:

(...) we encourage writing configurators to add the natures and builders you want based on what it available in the POM.

See this link for a guide and this project for some existing configurators for checkstyle, findbugs, pmd.

n00begon
  • 3,503
  • 3
  • 29
  • 42
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • That's what I was afraid of. An Eclipse-plugin version. Which means I have to configure each eclipse installation individually (or add a company-wide update site). Both of these are no-ops for me, so I guess I'll have to hack something together using GMaven :-) – Sean Patrick Floyd Nov 08 '10 at 10:42
  • 2
    @seanizer: My understanding is that the "configurators" do use the informations from the POM (e.g. the checkstyle configurator will use the checkstyle configuration from the pom). But you need indeed to install something. And indeed, this sucks hard now that I think about this again. – Pascal Thivent Nov 08 '10 at 10:56
  • 1
    The last sentence is true, of course. I want a pom-based solution that turns on all builders and natures I specify (which is silently ignored by eclipse if those builders and natures don't exist). Basically, I want the behavior of the maven-eclipse-plugin in m2eclipse (the way it used to be). Thx for your answer, BTW – Sean Patrick Floyd Nov 08 '10 at 10:57
  • @seanizer: Yeah, yeah, you're totally right and I wasn't thinking global enough => having to install a plugin is a pain. – Pascal Thivent Nov 08 '10 at 11:01
  • @Pascal actually, it would be even better if I could control that the plugins are actually present in eclipse (to enforce company policies). But I guess there's no maven-only solution for that (at least not without a huge hack). – Sean Patrick Floyd Nov 08 '10 at 11:05
  • @seanizer: The only (eclipse based) solution I'm aware of is the [Workspace Mechanic for Eclipse](http://google-opensource.blogspot.com/2010/05/introducing-workspace-mechanic-for.html) contributed by Google. It doesn't really enforce things but it does allow to manage a "corporate" workspace and to share it with everybody (with notifications, etc). I didn't play with it yet though, it's on my todo list. – Pascal Thivent Nov 08 '10 at 11:13
3

I have now implemented this as a maven plugin I call maven-eclipseconf-plugin. Unfortunately it's proprietary work for a client, so I can't share it. But let me describe what I do:

Tied to the lifecycle verify, I check for the existence of an eclipse .project file. If it's there, I check it for the presence of the builders and natures I want to automatically add (and you can deactivate this behavior by using a maven property or a stop file with a configurable name). You can also define configuration files that will be written (like .pmd, which is related to this other question of mine). The contents of the Configuration files can be specified inline, it can come from an external file, or from a URL. I also tried to introduce variable substitution in the config files where a special placeholder would be replaced with a multi-moduke-project's root folder, but I had to give up on that approach.

Anyway, the plugin gives me pretty much all the functionality of the maven-eclipse-plugin I ever used (of course there is a lot more though) and I'm happy with that. Perhaps I will build something similar once more in open source when this contract is finished.

Community
  • 1
  • 1
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
2

Project configurators are the proposed approach. But the latest version of m2e-extensions is from early 2010 and developed against m2eclipse 0.10.x. There is a successor project called m2e-code-quality which is more recent and active and developed against m2eclipse 0.12.x.

But neither m2e-extensions nor m2e-code-quality do support FindBugs at the moment. And there are some other limitations with header files, exclusions and modified JARs.

I have successfully used a universal approach with AntRun, Ant and XMLTask to automatically add project natures, builders and configuration files for Eclipse plugins from pom.xml.

Martin Ackermann
  • 1,066
  • 10
  • 15