Much ado about scripting, Linux & Eclipse: card subject to change


My First Maven Plugin

Having been working with Maven and Tycho for about the last 8 months, it was high time I got around to writing my first Maven plugin, because I need to break myself from my tendency to revert to ant and bash whenever I need to do something outside the normal Maven flow.

So, first I imported the git sources for Tycho 0.11.0-SNAPSHOT from so I'd have something from which to learn. Sure, Hello World samples are nice, but a working example is always more fruitful.

git clone

Next, I imported a few Tycho projects (tycho-p2-facade, tycho-p2-plugin, tycho-p2-publisher-plugin) from the git clone folder into Eclipse using m2eclipse 0.10.2. Because these are Maven projects and don't need Eclipse project clutter, there are no .project files and therefore they couldn't be imported as pre-existing projects.

So, I had to wobble through the New > Maven Project wizard a little until I figured out that I could check the 'Create a simple project (skip archetype selection)' box to create a new .project file in an existing project folder. Only wrinkle here is that if there's an existing pom.xml in a project, the New Maven Project wizard complains. The obvious workaround is to rename the existing pom.xml to pom.xml_, create the new Maven Project in w/ m2eclipse in the existing folder (as above), then replace the pom.xml that m2eclipse creates with the actual (renamed) one, pom.xml_ and refresh the project in Eclipse. Voila! I also updated the project settings to use JDK5 instead of the default JDK1.4. You need only do File > Import > Maven > Existing Maven Projects and browse for the pom files. So much easier than what I did above. Thanks to everyone for setting me straight!

So, with sample code to clone from it was time to create my own plugin project, then a second project on which that plugin depended in order to test the dependency chain thru Maven.

The first uses the "maven-archetype-plugin" archetype v1.1; the second, the "maven-archetype-quickstart" archetype v1.1. Here are the two projects:

  1. sample-plugin
  2. sample-project

The glue between these projects is in the sample-project's pom.xml:

And that's seemingly it. Next... adding actual useful functionality to a plugin, then using that functionality in our JBoss Tools build's parent pom.xml.


Max said...

if you use File > Import > Existing Maven Project (require m2eclipse installed) the projects should be possible to import withuot tweaking things.

mkleint said...

there is Import Maven Project import wizard that shall let you import a maven project into the workspace

Eugene Kuleshov said...

Eh? What was wrong with File / Import... / Maven / Existing Maven Projects or even directly check them out from git using Check out Maven projects from SCM?...

Mad Prophet said...

Couldn't you just use Import and then select "Existing maven project"?

If you use tycho there should be a m2eclipse plugin / configurator that will recognize eclipse artifacts (bundles, fragments). IIRC that should allow you to create correct .project file.

Please correct me if I'm wrong.