27 January 2021

An OSGi bundle that exports the javax.inject package.

Since a couple of years, the Eclipse platform jars are published on maven central with metadata that allows the consumption in a traditional maven project (no Eclipse Tycho required).

This article is my feedback after having experimented with PDE (the Plug-in Development Environment project).

The problem

The goal is to compile and execute code that requires this OSGi bundle from maven-central:

<dependency>
  <groupId>org.eclipse.pde</groupId>
  <artifactId>org.eclipse.pde.core</artifactId>
  <version>3.13.200</version>
</dependency>

I am using a regular maven project (with the bnd plugins to manage the OSGi related tasks). I do not have Eclipse Tycho, so maven do not have access to any P2 Update Site.

Amongst all dependencies of PDE, there is org.eclipse.e4.core.contexts and org.eclipse.e4.core.services. Those two bundles requires:

Import-Package: javax.inject;version="1.0.0",

Source: here and here.

So we need a bundle exporting this package, otherwise the requirements are not fulfilled and I get this error:

[ERROR] Resolution failed. Capabilities satisfying the following requirements could not be found:
    [<<INITIAL>>]
      ⇒ osgi.identity: (osgi.identity=org.eclipse.pde.core)
          ⇒ [org.eclipse.pde.core version=3.13.200.v20191202-2135]
              ⇒ osgi.wiring.bundle: (&(osgi.wiring.bundle=org.eclipse.e4.core.services)(bundle-version>=2.0.0)(!(bundle-version>=3.0.0)))
                  ⇒ [org.eclipse.e4.core.services version=2.2.100.v20191122-2104]
                      ⇒ osgi.wiring.package: (&(osgi.wiring.package=javax.inject)(version>=1.0.0))
    [org.eclipse.e4.core.contexts version=1.8.300.v20191017-1404]
      ⇒ osgi.wiring.package: (&(osgi.wiring.package=javax.inject)(version>=1.0.0))

In the P2 world

The bundle javax.inject version 1.0.0 is available in the Eclipse Orbit repositories.

In the maven world

The official dependency

The dependency used by most of the other libraries:

<dependency>
  <groupId>javax.inject</groupId>
  <artifactId>javax.inject</artifactId>
  <version>1</version>
</dependency>

This library does not contain any OSGi metadata in the published MANIFEST.MF.

See the corresponding open issue.

Tom Schindl’s solution

The jar from Eclipse Orbit is available at:

<dependency>
  <groupId>at.bestsolution.efxclipse.eclipse</groupId>
  <artifactId>javax.inject</artifactId>
  <version>1.0.0</version>
</dependency>

But this is not on maven central. You will need to add following repository to your pom.xml:

<repositories>
  <repository>
    <id>bestsolution</id>
    <url>http://maven.bestsolution.at/efxclipse-releases/</url>
  </repository>
</repositories>

On maven central

This question on stackoverflow gives some inputs and suggests:

From the Apache ServiceMix project:

<dependency>
  <groupId>org.apache.servicemix.bundles</groupId>
  <artifactId>org.apache.servicemix.bundles.javax-inject</artifactId>
  <version>1_3</version>
</dependency>

From the GlassFish project.

<dependency>
  <groupId>org.glassfish.hk2.external</groupId>
  <artifactId>javax.inject</artifactId>
  <version>2.5.0-b62</version>
</dependency>

After analyzing other candidates in list where artifactId == "javax.inject", there is also this one from the Lucee project:

<dependency>
  <groupId>org.lucee</groupId>
  <artifactId>javax.inject</artifactId>
  <version>1.0.0</version>
</dependency>

And on twitter Raymond Augé suggested the Apache geronimo project.

<dependency>
  <groupId>org.apache.geronimo.specs</groupId>
  <artifactId>geronimo-atinject_1.0_spec</artifactId>
  <version>1.2</version>
</dependency>

Make your choice.


Post source on GitHub