Problem with new addon and dependencies packaging

I started to develop an add-on to support InfluxDB v2, firstly for personal use to play with new InfluxDB APIs and features but also to get some experience with Openhab addons developments.
Now it’s only personal but I want to do in the correct way to be able to ask if it can be integrated in the future.

I started making a copy of @dominikkv work in https://github.com/dominikkv/openhab2-addons/tree/influxdb-neo and done some refactors and changes to adapt to the new and incompatible InfluxDB2 API, I named the copy org.openhab.persistence.influxdb2.

After some work I had a first parcial work to try and started to deploy it to local development 2.5.0 openhab snapshot and then the problems started :slight_smile:

The dependencies that I need for the module are:
com.influxdb:influxdb-client-java:1.2.0
com.influxdb:flux-dsl:1.2.0
And it’s dependencies that are quite a lot.

I read OpenHab documentation regarding Osgi and I started with the dependencies and the pom and this in feature.xml:

<bundle dependency="true">wrap:mvn:com.influxdb/influxdb-client-java/1.1.0$Bundle-Name=InfluxDBClientJava&amp;Bundle-SymbolicName=com.influxdb.influxdb-client-java&amp;Bundle-Version=1.1.0"</bundle>
<bundle dependency="true">wrap:mvn:com.influxdb/flux-dsl/1.1.0$Bundle-Name=InfluxDB Flux DSL&amp;Bundle-SymbolicName=com.influxdb.flux-dsl&amp;Bundle-Version=1.1.0"</bundle>

I realized that I will also need to include the transitive dependencies and I added also using mvn and wrap:mvn dependencies

As karaf was complaining about not found dependencies I started to check in console and I was not able to see that dependencies deployed.

Then I decided to reduce it to the minimum expression and do a new empty module using addon wizard and add only one of the dependencies as a module. That is an empty pom.xml and this in feature.xml:

<feature>openhab-runtime-base</feature>
<feature prerequisite="true">wrap</feature>
<bundle dependency="true">wrap:mvn:io.gsonfire/gson-fire/1.8.0</bundle>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.mytestbinding/2.5.0-SNAPSHOT</bundle>

With this I realized that the wrapped modules doesn’t install in Karaf, searching I found this issue about problems with wrapped modules, and the fact that in 2.5.0 there won’t be wrapped modules, and instead OSGi adaptions are made and uploaded to a repository.

My questions are:
How I had to proceed to develop my module?
I understand that I can’t upload new modules to the OSGi repository.
What is the easiest way to proceed for me to develop locally and test my module? Do the wrapped modules with Bnd and deploy manually to Karaf?
And what is the way to proceed if in the future I want to ask to integrate it with OpenHab.
Is ther any updated documentation?

2 Likes

The simplest first step would be just put every library in the lib folder. Then you should be able to develop the binding. When you want to include the binding in the openHAB repo you can work out the correct inclusion of the libraries. There is updated documentation on libraries. But I think it can use some more information: https://www.openhab.org/docs/developer/buildsystem.html

There is also a draft pr to migrate the persistence services from oh1 to oh2. This can give you some insight into were things are going: https://github.com/openhab/openhab2-addons/pull/5275

Thank you very much, Hilbrand.
I don’t read your message until now and I started two days ago to create OSGi packages using bnd command line.

Something like:

retrofit2.bnd

 -classpath: retrofit-2.5.0.jar
Bundle-SymbolicName: com.squareup.retrofit2
ver: 2.5.0
-output: ${bsn}-${ver}.jar
Bundle-Version: ${ver}
Import-Package: !retrofit2.*,okhttp3.*;version="[3.13,3.14)",!android.*,!javax.annotation.*,!kotlin.*,*
Export-Package: *;version=${ver}

and creating a package with bnd retrofit2.bnd

And that for the other 11 non-OSGi dependencies of the driver, only 3 were OSGi packages.
This will be valid for a future incorporating the addon to openhab codebase? It was very laborious, but now the addon correctly deploys and starts.

I took a small look at Draft and I’ve seen that influxdb2 dependencies are in lib, this is valid only for development or also as a final solution?

Finally, I already read the documentation you said, but it doesn’t seem alienated with this issue as it talks about wrapping that doesn’t seem to be the correct way for 2.5.0 addons, does it?

I’ll haven’t looked into the whole libraries part very deeply and it has been the part that was has been improved several times this year, so I’m not completely up-to-date. But there is a separate repository where the osgified versions of libraries are kept. I would guess any library needed to be osgiy should be there: GitHub - openhab/openhab-osgiify: OSGi-ified versions of openHAB dependencies

The draft was started some time ago and postponed to be picked up after the openHAB release. So the way the libraries are used in there might need some changes to the lastest insights, but I don’t know if that is really needed.