I’m starting to use the p2-maven-plugin in order to integrate non-OSGi JARs into our project in a (hopefully) convenient manner.
I have an artifact which I want to OSGi-ify, called com.thirdparty.artifact
. I’m current using p2-maven-plugin’s standard configuration, and I list my artifact in the pom.xml
like so:
<artifact><id>com.thirdparty:artifact:1.2.3</id></artifact>
This artifact has a transitive dependency called com.thirdparty:library:2.5
, which exports a package com.thirdparty.library
which is in turn imported by com.thirdparty:artifact
. When I run mvn p2:site
, I get a P2 site which contains com.thirdparty:artifact:1.2.3
and com.thirdparty:library:2.5
-- all fine so far.
Now, things are turning messy. My existing target platform already contains an artifact called com.othervendor:library
(different vendor, it’s there and I cannot change that), which also exports the very same package com.thirdparty.library
(but an entirely different version).
At runtime, the OSGi/Eclipse black magic (which I’ll probably never fully understand) tries to resolve com.thirdparty:artifact
’s dependency on the package com.thirdparty.library
using the com.othervendor:library
and not my provided com.thirdparty:library:2.5
-- and I’m obviously in trouble. Here’s a visualization of my situation:
Being absolutely no OSGi rocket scientist, my first idea was to inspect the MANIFEST.MF
in com.thirdparty:artifact
. Beside others, this shows the following:
Import-Package: com.thirdparty.library
So, this obviously just tells com.thirdparty:artifact
to import this package from some bundle, and OSGi/Eclipse thinks “okay, com.othervendor:library
is more adequate than com.thirdparty:library
”.
There seem to be two methods of narrowing down the dependencies to actually use. However: I’m not sure (a) how to integrate them into my p2-maven-plugin
workflow, and (b) I do not understand why p2-maven-plugin
does not automatically require the concrete package version in the Import-Package
directive (this information is after all already specified in the source pom.xml
).
Probably I’m not seeing the forest for the trees here. So any general advice beside my questions above is very welcome!
[edit] Here’s my pom.xml
(the concrete library which I’m about to OSGi-ify is Selenium):
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>com.example.p2dependencies</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.reficio</groupId>
<artifactId>p2-maven-plugin</artifactId>
<version>1.2.0</version>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<artifacts>
<artifact><id>org.seleniumhq.selenium:selenium-java:3.4.0</id></artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
[edit2] Problem seems to be solved, it seems, the issue was an additional package which was only exported by com.othervendor:library
.