Hi folks,
Im totally stuck to include any kind of rest client in my binding.
Currently Im developing a Binding for a Siemens Coffeemaker which we want to use in a research project at University (and maybe publish later if there is a need ).
I already created a standalone Java CLI Application which uses the retrofit2 rest client lib. I can’t get the code working inside the OpenHAB 3 Binding.
The error is: Unresolved requirement: Import-Package: okhttp3
I do not think you need to specify the dependency in feature.xml since you compile in the dependency. You need to make sure bnd does not add the dependency as osgi requirement (once again that would be unnecessary since they are compiled in) – do this via bnd.importpackage
Also note that there is a recommendation to use already existing dependencies for some default libraries - HTTP clients being one of them. Refer to Coding Guidelines | openHAB (“Default libraries”)
Thanks for the hint, @ssalonen! Its working now. Wuhuuu
@pravussum
There are cases in which you don’t want to reinvent a REST-Client. A lot of existing OpenHAB addons are rellying on okhttp including the OpenHAB cloud connector. Retrofit (Generator for REST clients) uses okhttp and my needed SSE-client uses okhttp too.
Is it possible to include those frequently used libraries in the runtime in the future?
I switched from Jackson to Gson because I saw that Gson is the preferred way (mentioned in the guidelines).
Now my pom.xml looks like this. Is this really the way to go to include all transitive dependencies manually and exclude them from BND? Feels a little bit like a workaround…
I’m by no means an OSGI expert, but this is the way I ended up doing it in a PR (felt the same way about the transitive dependencies). Got no feedback yet, but it compiles and works
It helps a lot to have a look at the created manifest in the compile output directory and try to understand how OSGI, Karaf and the bnd / Maven plugins play together. Took me a while of reading, but otherwise the trial&error method will probably get you nowhere.