Reficio™ - Reestablish your software!

Eclipse RCP dependency management done right with p2-maven-plugin

I am happy to announce the fourth official release of the p2-maven-plugin -> version 1.1.0! I managed to find some time to work on the Maven 3.1.x compatibility issues that have been finally fixed (…hmmm actually, I’ve managed to find a lot of time, since I’ve been hacking for the last 48 hours ;) ) I also refactored the code, so it should be more clean and readable now! The test coverage is awesome… as always – it averages at around 95%. I am especially proud of the end-to-end integration tests as that’s where most of the test-coverage comes from. It was really easy to refactor the code having such great tests!

It’s been a lot of work to release four versions in the last 10 months, even though that the codebase is relatively small – but the devil is in the details – especially when it comes to OSGi and Tycho :) . It was, however,a lot of fun and satisfaction to see that people appreciate your work and that the plugin is used more and more widely! I will try to post an article about the projects that use p2-maven-plugin soon.

In the meantime grab version 1.1.0 as it is still hot:

What is the p2-maven-plugin?

Are you familiar with the automated dependency management like in Maven, Gradle or any other fancy tool? You just define a project descriptor, add a bunch of dependencies and everything happens “automagically”… Piece of cake huh?! Well, there are, however, these RCP “unfortunates” for whom it is not quite that easy… Why’s that, you might think?

The following blog entry outlines the problem perfectly: The author presents five different approaches how to configure the build and dependency management in a Tycho / Eclipse RCP project and, in the end, she couldn’t really propose a satisfactory solution!

In order to add a third-party dependency to an Eclipse RCP project the dependency has to reside in a P2 update site.
So in order to generate such site you have to do three things by-hand:

  • 1. download all required dependencies to a folder,
  • 2. recognize which dependencies are not OSGi bundles and bundle them using the ‘bnd’ tool,
  • 3. take all your bundles and invoke a P2 tool to generate a P2 update site.

Ufff, that is a mundane, cumbersome, repeatable and stupid activity that may take you a few hours – imagine now that you have to do it multiple times… That’s where p2-maven-plugin authored by me comes into play. It solves problems #1, #2, #3 and does all the hard work for you. Isn’t that just brilliant? I think it is… :)

How to use it in 2 minutes?

Using p2-maven-plugin is really simple. I have prepared a quickstart pom.xml file so that you can give it a try right away. We will generate a P2 site with a couple of OSGi bundles (bundling some of them on the fly) and and then we will expose it using the jetty-maven-plugin.

The full code of the example is located HERE. There’s more examples HERE

In order to use the plugin the following section has to be added to your pom.xml file:

The plugin hasn’t been deployed to Maven Central so far – I would appreciate help on this issue!

Here’s the pom.xml:

There are many more config options, but basically that’s the thing that you need for now. In order to generate the site invoke the following command ‘mvn p2:site’ in the folder where the pom.xml file resides. When the process finishes your P2 site is ready!

You will see the following output:

Your site is located in the target/repository folder and looks like this:

Unfortunately, it’s not the end of the story since Tycho does not support local repositories (being more precise: repositories located in a local folder). The only way to work it around is to expose our newly created update site using an HTTP server. We’re gonna use the jetty-plugin – don’t worry, the example above contains a sample jetty-plugin set-up. Just type ‘mvn jetty:run’ and open the following link http://localhost:8080/site. Your P2 update site will be there!

Now, simply reference your site in your target definition and play with your Eclipse RCP project like you were in the Plain Old Java Environment. Remember to enable the “Group items by category” option, otherwise you will not see any bundles.

Would you like to read more?:
Thanks for reading!