Best practice to add a maven dependency to an Eclipse RCP Plugin
Asked Answered
G

1

6

I want to add some GitHub projects as dependencies to my Eclipse RCP Plugin. The GitHub projects are oshi and leshan.

Both GitHub projects provide maven builds over maven central which i could use.

But as i understand so far i cant use these builds directly in an Eclipse RCP Plugin because it requires OSGI-Bundles - in contrast to an "classic" Eclipse Java project.

So far i found three ways of dealing with this problem:

I also looked into Tycho but as far as i understand you can only add a p2 repository as a dependency in Tycho, which leads again to the problem of creating one.

Is there another/better way of dealing with Non-OSGI-Bundle Maven builds in an Eclipse RCP Plugin?

EDIT: i found for me the best way to use gradle (a gradle plugin bnd-platform), to automatically resolve the dependencies using maven central and create a local p2 repository, described in Option 1 here https://mcmap.net/q/995049/-convert-existing-jar-to-osgi-bundle

Gaddy answered 6/9, 2019 at 10:24 Comment(4)
No, there is no better way. In Maven modules/bundles are resolved on compile/build time whereas in OSGi bundles can be started and stopped at run time. For this in OSGi a JAR must contain additional metadata and a p2 repository must contain metadata to resolve also imported packages. So you first have to convert the JAR into a OSGi bundle (or ask the vendor of the JAR to do this) and then create a local p2 repository via Tycho tycho-p2-extras:publish-features-and-bundles.Protolanguage
Thanks for making it clear to meGaddy
I'm the lead maintainer of OSHI. I thought we were already publishing OSGi bundles via the bnd-maven-plugin. Am I mistaken? Is there something I need to configure?Bunk
Yeah your right, looks like OSHI is already a OSGi bundle. Sorry for the inconvenience.Gaddy
C
6

Recently the Eclipse Maven (M2E) implemented tight integration of Java libraries from Maven central into the target platform. With this, you can easily add Java libraries to your target platform and they can be converted (if necessary) on the fly to OSGi bundles including their dependencies.

See https://www.vogella.com/tutorials/EclipseJarToPlugin/article.html for how to using Java libraries (from Maven Central) for OSGi, Eclipse Plug-in and Eclipse RCP development.

This extension is also supported with the latest Maven Tycho version for command line builds, see https://www.vogella.com/tutorials/EclipseTycho/article.html

Carnet answered 21/1, 2021 at 8:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.