3rd party Maven dependencies in openhab core

What would be the “right” way to include a third party maven dependency in the openhab-core bundle?

I’m developing a PR in a openhab-core bundle (openhab-core/bundles at master · openhab/openhab-core · GitHub) where I depend on a third party maven artifact.

My current assumption is the following:

  • I have to declare the dependency in the bundles POM (using provided or compile scope)
  • I have to add a Karaf feature to the openhab-tp feature.xml since it seems external dependencies are all kept there (I found none in openhab-core itself). This feature has to include a bundle dependency using "mvn: " notation, referencing my 3rd party maven artifact.
  • I have to add “feature dependency” in the feature.xml of openhab-core where the new openhab-tp feature is referenced
  • since my 3rd party maven dependency still isn’t found I figured it is not “OSGI ready”, so I forked and updated GitHub - openhab/openhab-osgiify: OSGi-ified versions of openHAB dependencies creating an osgiified version of the 3rd party dependency which I use instead the real one
  • Most likely I have to add my Maven dependency to the runtime POM ?

My questions:

  • is that really the right approach?
  • is really all of that necessary?
  • am I missing something?
  • doing all this, the openhab-core karaf-maven-plugin complains about a transitive dependency of my 3rd party dep being missing (ch.qos.logback.classic in that case) - where do I have to make a change? And I guess we don’t really want to have logback being included, so maybe the 3rd party artifact needs to be adapted?

Some clarification or a pointer to some enlightening documentation would be much appreciated.

Here are my findings so far (including some advise here):

  • “private” core dependencies (read: only relevant for the bundle itself, not to used by any other) are compiled into the classes output using the maven-dependency-plugin. Refer to the core audio bundle for an example
  • core dependencies that might be relevant for others should be declared as features. One could theoretically use Karafs wrap feature here but this “causes issues when for instance debugging the code in non-Karaf environments. E.g. it won’t work when running the Demo App in Eclipse.”
  • when developing bindings, its enough to declare the dependency in the POM with scope “compile” to have it compiled (“embedded”) in the resulting JAR. Refer to Build System | openHAB. Note the diff between the screenshot and the description: scope “compile” works here.
    • note that optional transitive dependencies are apparently not included in the compile output. But their packages ARE generated into the bundles manifest file ([compile output]/classes/META-INF/MANIFEST.MF) as Import-Package and will consequently fail the verify step during build. You have to tell BND that they are optional by adding a corresponding bnd.importpackage property to the POM.

      <properties>
      <bnd.importpackage>com.optionalpackage.*;resolution:=optional</bnd.importpackage>
      </properties>

4 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.