Building a Java library for use by a binding

Hello everyone! I need help from someone who knows Maven, i guess…

I am working on rewriting OpenSDG library in Java. It will make better friendship with Maven repositories and finally enable to upstream my Danfoss binding.

For now i have the first release candidate of the library, working with the test app; and i started to adapt my binding. I’ve thrown away native binaries, “lib” folder with the JNI glue, and added a dependency to my library to pom.xml:

<dependency>
  <groupId>org.opensdg</groupId>
  <artifactId>osdg_java</artifactId>
  <version>1.0</version>
</dependency>

It all looks good, Maven sees the dependency, it finds it from the workspace, the binding builds. But when i try to resolve app.bndrun i get “missing dependency” error. osdg_java appears to be missing.

I’ve examined jar contents. My binding also uses org.json, and from this i know that dependencies, which aren’t part of openhab core, will be automatically bundled in the binding’s .jar. Previously exactly this happened to org.json. Now, with the new version, dependency resolution magically stops working. I see neither opensdg nor org.json in the binding .jar.

Also, my library in turn uses some more libraries: jnacl and protobuf. These dependencies are also missing from my library’s jar. I am nor sure whether this is supposed behavior or not. Google told me that a plugin called maven-assembly-plugin is responsible for this behavior. For test purposes i tried to add it (as suggested, for instance, here java - Including dependencies in a jar with Maven - Stack Overflow ) to opensdg’s pom.xml No result, nothing changed, my dependencies are not linked in.

Could anyone kindly explain me what i am doing wrong? Frankly speaking i don’t understand Maven plugins and goals at all, so i am even unable to diagnose the problem myself.

Library’s code is here: GitHub - Sonic-Amiga/opensdg-java: Free and open SecureDeviceGrid protocol client side implementation in Java
Binding’s code is here: GitHub - Sonic-Amiga/org.openhab.binding.devireg at opensdg-java . See branch named “opensdg_java” for the modified version.

Did you try explicitely setting the scope to compile?

@J-N-K Sorry, what’s scope to compile and how to set it?
This implies “no” answer :slight_smile:

<dependency>
  <groupId>org.opensdg</groupId>
  <artifactId>osdg_java</artifactId>
  <version>1.0</version>
  <scope>compile</scope>
</dependency>

Thahk you, just found an explanation of these on the Net. I’ve got one suggestion of what can be bad, I’ll reply after testing

It changed nothing. I tried to reduce the problem myself and started from original version of the binding (which compiles well) and added a dummy test library, made from scratch.
For some reason the test library is still not bundled in the jar, but somehow resolution works and i am even able to run the resulting code. org.json comes bundled.
I don’t know why and how it works. I’ll try to populate my dummy lib with other dependencies until it breaks.

So far am still experimenting.

I have populated my dummy mock library with all the dependencies the real library has. It has a single call, like “static doStuff()”, i just adding this call to master branch of libopensdg. And everything works. :frowning:

It’s sad because if i try to link in my opensdg-java everything breaks down. In this configuration “Missing dependency” error does not pop up during resolution, but when i try to run the resulting bundle, i get this error:

! could not resolve the bundles: [org.openhab.binding.danfoss-2.5.9.202104082056 org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.danfoss [135]
  Unresolved requirement: Import-Package: io.swagger.annotations; version="[1.5.0,2.0.0)"; resolution:="optional"
  Unresolved requirement: Import-Package: org.opensdg.java; version="[1.0.0,2.0.0)"
    -> Export-Package: org.opensdg.java; bundle-symbolic-name="org.opensdg.osdg_java"; bundle-version="1.0.0"; version="1.0.0"; uses:="org.opensdg.protocol,org.opensdg.protocol.generated"
       org.opensdg.osdg_java [139]
         Unresolved requirement: Import-Package: com.google.protobuf; version="[3.1.0,4.0.0)"
           -> Export-Package: com.google.protobuf; bundle-symbolic-name="com.google.protobuf"; bundle-version="3.1.0"; version="3.1.0"
              com.google.protobuf [137]
                Unresolved requirement: Import-Package: sun.misc

How come sun.misc is gone? Isn’t it a part of the JVM ?

I am completely baffled and don’t know what to do and why things break. As usual, all the codes are available (except dummyLib, but its pom.xml is 1:1 copy of opensdg-java (minus the name of course).

Switched to “opensdg-java” branch of my binding and re-tested. So far, resolution error is gone, but “unresolved sun.misc” persists. What’s the problem here? Anyone, HELP!

I’ve tried googling and found these links:

https://search.maven.org/artifact/com.diffplug.osgi/com.diffplug.osgi.extension.sun.misc/0.0.0/jar

I’ve added the suggested fragment:

<dependency>
  <groupId>com.diffplug.osgi</groupId>
  <artifactId>com.diffplug.osgi.extension.sun.misc</artifactId>
  <version>0.0.0</version>
</dependency>

to my binding’s pom.xml and it didn’t help. What am i doing wrong? Is it forbidden to use protobuf in openhab ?

I solved the problem by using the latest version of protobuf (3.15.8). Thanks to everyone for silence, encouraging me to find a solution myself and learn the hard way. :wink:

1 Like