maintain library project for Maven and Eclipse RCP/ OSGi in the same repository

If you are working both in the Maven and the Eclipse RCP/ OSGi universe, you might find it quite frustrating that these two worlds cooperate so poorly. In order to use the same library in both worlds, a lot of error-prone copy-and-paste is needed, at least if you would like to use this project in a Maven and Maven Tycho build.

In principle, there is not much that is different for a Maven artifact and an Eclipse RCP/ OSGi Plug-in:
In an Eclipse RCP/ OSGi Plug-in you just need an additional META-INF/MANIFEST.MF and build.properties file. The problem comes with the Maven pom file, which looks completely different for standard Maven and Maven Tycho. Luckily, you can specify the name of the pom file when invoking Maven:

Therefore, you can just maintain two pom files and with only few limitations, it is possible to maintain a library that can be used in a standard Maven build and in a Maven Tycho build within the same repository:

  1. Modify your .gitignore so that it contains the following lines:
    bin
    .project
    .settings
    .classpath
    
    We don’t want to have any Eclipse project configuration information in the project, since we want to be able to import it both as ‘Maven project’ and ‘Eclipse/ OSGi project’.
  2. Remove all files from the git index that match the pattern above.
    • If your project is a Maven project, right-click on the project and select ‘Configure -> Convert to Plug-in project’. This will create the META-INF/MANIFEST.MF and build.properties files.
    • If your project is a Plug-in project, right-click on the project and select ‘Configure -> Convert to Maven project’. This will create the pom.xml file.
    These steps are optional and only needed if you are missing either pom.xml or META-INF/MANIFEST.MF and build.properties .
  3. Create the Tycho pom file, name it e.g. pom-tycho.xml. It’s content should look like this:
  4. Commit all changes and delete the project from your workspace.
  5. Import the project using the ‘Import Existing Maven Project’ or ‘Checkout Maven Project from scm’ wizard. To use the project as an Eclipse RCP/ OSGi Plug-in project, disable it’s Maven nature via ‘Maven -> disable Maven nature’.
  6. Done!
Note: You manually need to keep in sync the version strings in pom.xml, META-INF/MANIFEST.MF and pom-tycho.xml! E.g. after running a Maven release, you need to adapt the version numbers in META-INF/MANIFEST.MF and pom-tycho.xml so that they match the automatically changed version strings in pom.xml.
Also note that you cannot use a Bundle Activator in this project. If you need one, just create another Eclipse-RCP Plug-in that depends on your library and contains a Bundle Activator.

Troubleshooting: After importing as Maven project or converting to Maven project, you might run into build-path problems. Try to resolve using ‘right-click on project -> Maven -> Update Project..’ And/ or fix the Java Build Path of the project (Standard Eclipse source folder is src, in Maven it is src/main/java). java-build-path

Working Set specific Problems View

If you are working with many different projects, Eclipse let’s you organize them into “Working Sets”. You can add projects to different Working Sets and configure your Package Explorer to show only certain Working Sets.

assign_working_sets working_sets_assignments

The Eclipse “Problems View” nevertheless, shows per default all Errors and Warnings from all projects open in your current workspace.

To change the default behaviour you can configure the default Problems View and even create a new one:

Click on the tiny triangle on the right side of the Problems View to open a configuration window.

problems_view_configure_1 problems_view_configure_2

Here you can change the default behavior to show only errors and warnings for the current selection or to show errors and warnings for a specific working set.

The latter is especially interesting in combination with creating a new Problems View. You can for example create a Problems View for each working set and then configure it to show only the problems of the specific working set.

This way you can create Working Set-specific Problems Views and for example configure the default one to show only the current selection. This will give you some extra flexibility when working with many different projects.