From the beginning, Maven

For years, Nuxeo has been using Maven to manage its builds and dependencies. It provides great out of the box tools for building, packaging and setting up projects. Setting up Maven projects can be done in two ways: using Maven-eclipse-plugin (mvn eclipse:eclipse) or using m2-eclipse plugin. Both generate a project classpath with links to dependencies in the m2 repository.


On another side, OSGi


Nuxeo is also trying to be as close as possible to the OSGi standard. Nuxeo Apogee project has been experimenting with the uses of a full Nuxeo repository inside the Eclipse platform (Equinox) and it works! Developers did, however, experience some difficulties as they had to deal with Maven and OSGi different ways of managing dependencies.


Why is it hard?


When a project is setup in Eclipse as a OSGi bundle, we have lots of advantages:



  • The IDE is providing tools to manage OSGi package and bundle dependencies,

  • It is easy to launch and debug a RCP application with OSGi bundles from Eclipse.


The problems are:



  • Maven has its resources (META-INF/MANIFEST.MF for instance) located in src/main/resources. On the other hand, these resources should be located in the root folder in Eclipse PDE,

  • When working in OSGi mode, you may break your Maven dependencies,

  • It is not possible to load the same project in the two modes at the same time,

  • Maven unit tests can't be launched in OSGi mode.


We tried ...


We have written a eclipse builder to synchronize resources from src/main/resources to the root folder of the project and to add the plug in nature to the project. Thought it is working quite well, it didn't solve the problem of not being able to run Maven unit tests. Finally, the builder had side effects and was overriding files with the wrong version from time to time.


Another solution would have been to make Nuxeo work with Tycho (http://www.eclipse.org/proposals/tycho/). We didn't take that route as it would have involved changing our Maven project layouts.


The magic trick


A few weeks ago, we finally found a trick that would resolve most of our problems. The solution was to make src/main/resources the root of the OSGi project and add a link to ../java to have the src folder available. And THIS IS WORKING with Eclipse Helios (last version of Eclipse)!


The link is done in the .project file with:


    <linkedResources>
        <link>
            <name>src</name>
            <type>2</type>
            <locationURI>PARENT-1-PROJECT_LOC/java</locationURI>
        </link>
    </linkedResources>


Try it right away


In your plugin, copy the provided .project and .classpath files in src/main/resources/. Replace the project name with yours in the .project file (should be unique in the workspace).


We have also written a Maven plugin to generate these files. Available in nuxeo development branch with the commands (need to update maven-nuxeo-plugin with 1.0.15-SNAPSHOT version):


mvn nuxeo:initpde to create the files.

mvn nuxeo:cleanpde to clean them.