Skip to content

Building POM first projects

Dénes Harmath edited this page Jul 8, 2014 · 2 revisions

Using POM-first artifacts

A tutorial on using Maven dependencies in Eclipse plug-ins (which of course are OSGi bundles): http://wiki.eclipse.org/Tycho/How_Tos/Dependency_on_pom-first_artifacts

A very important limitation:

p2 metadata is generated for all maven dependencies. Currently this only works for OSGi bundles, all other dependencies are silently ignored.

The project in question: http://git.eclipse.org/c/tycho/org.eclipse.tycho-demo.git/tree/itp02/

The most important projects are:

pomfirst-thirdparty

pomfirst-thirdparty does not have any sources itself, but "wraps" thirdparty library available from maven repository in an OSGi bundle.

The packaging of this project is set to bundle.

In Eclipse, the project throws an error at first: Lifecycle mapping "org.sonatype.tycho.m2e.wrapperBundle" is not available. To enable full functionality, install the lifecycle mapping and run Maven->Update Project Configuration.

Unfortunately, there is no org.sonatype.tycho.m2e.wrapperBundle available in the m2e Marketplace. The solution (?) is to comment out the org.eclipse.m2e:lifecycle-mapping plug-in in the POM file.

The required packages must be imported and then exported in the MANIFEST.MF file:

Export-Package: org.codehaus.plexus.util
Import-Package: org.codehaus.plexus.util

tycho.demo.itp02.bundle

The packaging of this project is eclipse-plugin.

The MANIFEST.MF defines a dependency on the pomfirst-thirdparty project and imports the required packages:

Import-Package: org.codehaus.plexus.util
[...]

The Require-Bundle: tycho.demo.itp02.pomfirst-thirdparty is not necessary, the appropriate plug-in is determined automatically.

After this, you can use the classes defined in the package:

import org.codehaus.plexus.util.StringUtils;

[...]

public static void main(String[] args) {
    System.out.println(StringUtils.capitaliseAllWords("hello"));
}

Pay attention to the version numbers (MANIFEST.MF: .qualifier, pom.xml: -SNAPSHOT).

If you are building a multi-module Tycho project, be sure to include the POM-first dependencies in the parent project.

It is possible that you need to go through use a "clean procedure hack":

  • delete all related projects from Eclipse (but not from the disk)
  • restart Eclipse
  • import the projects you just deleted
  • the tycho.demo.itp02.bundle project will now see the Plexus util packages.
Clone this wiki locally