Not able to add dependency to a binding

Hi

I am building my first binding, but ran in to some building issues. I am quite new to Java and Maven, so I am probably missing something basic…??

My development environment is set up according to https://www.openhab.org/docs/developer/#setup-the-development-environment, using VSCode as IDE. I am able to create the skeleton using this command “create_openhab_binding_skeleton.cmd” and it compiles fine using “mvn clean install -DskipChecks” within the binding.

But as as soon as I add dependencies like below, it will no longer build.

<dependency>
      <groupId>com.jayway.jsonpath</groupId>
      <artifactId>json-path</artifactId>
      <version>2.4.0</version>
      <scope>compile</scope>
    </dependency> 

The new binding is added to pom.xml (in bundles folder) as a module

<module>org.openhab.binding.met</module>

Anything else I need to do in order to add dependencies?

I am not aloud to upload files so I just add an extract of the build log here.

First applicable warning:
[WARNING] Feature resolution failed for [openhab-binding-met/2.5.7.SNAPSHOT]
Message: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=openhab-binding-met; type=karaf.feature; version=2.5.7.SNAPSHOT; filter:="(&(osgi.identity=openhab-binding-met)(type=karaf.feature)(version>=2.5.7.SNAPSHOT))" [caused by: Unable to resolve openhab-binding-met/2.5.7.SNAPSHOT: missing requirement [openhab-binding-met/2.5.7.SNAPSHOT] osgi.identity; osgi.identity=org.openhab.binding.met; type=osgi.bundle; version="[2.5.7.202007181104,2.5.7.202007181104]"; resolution:=mandatory [caused by: Unable to resolve org.openhab.binding.met/2.5.7.202007181104: missing requirement [org.openhab.binding.met/2.5.7.202007181104] osgi.wiring.package; filter:="(osgi.wiring.package=com.fasterxml.jackson.core)"]]
Repositories: {
file:C:\Users\oyste\Development\openhab-addons\bundles\org.openhab.binding.met\target/feature/feature.xml
mvn:org.apache.karaf.features/framework/4.2.7/xml/features
mvn:org.apache.karaf.features/standard/4.2.7/xml/features
mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/2.5.0/xml/features
mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-tp/2.5.0/xml/features
mvn:org.ops4j.pax.web/pax-web-features/7.2.11/xml/features
}

First error:
[ERROR] Failed to execute goal org.apache.karaf.tooling:karaf-maven-plugin:4.2.7:verify (karaf-feature-verification) on project org.openhab.binding.met: Feature resolution failed for [openhab-binding-met/2.5.7.SNAPSHOT]
[ERROR] Message: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=openhab-binding-met; type=karaf.feature; version=2.5.7.SNAPSHOT; filter:="(&(osgi.identity=openhab-binding-met)(type=karaf.feature)(version>=2.5.7.SNAPSHOT))" [caused by: Unable to resolve openhab-binding-met/2.5.7.SNAPSHOT: missing requirement [openhab-binding-met/2.5.7.SNAPSHOT] osgi.identity; osgi.identity=org.openhab.binding.met; type=osgi.bundle; version="[2.5.7.202007181104,2.5.7.202007181104]"; resolution:=mandatory [caused by: Unable to resolve org.openhab.binding.met/2.5.7.202007181104: missing requirement [org.openhab.binding.met/2.5.7.202007181104] osgi.wiring.package; filter:="(osgi.wiring.package=com.fasterxml.jackson.core)"]]
[ERROR] Repositories: {
[ERROR] file:C:\Users\oyste\Development\openhab-addons\bundles\org.openhab.binding.met\target/feature/feature.xml
[ERROR] mvn:org.apache.karaf.features/framework/4.2.7/xml/features
[ERROR] mvn:org.apache.karaf.features/standard/4.2.7/xml/features
[ERROR] mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/2.5.0/xml/features
[ERROR] mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-tp/2.5.0/xml/features
[ERROR] mvn:org.ops4j.pax.web/pax-web-features/7.2.11/xml/features
[ERROR] }

You need to add the dependency to the feature file too. But is there a reason you’re using jsonpath instead of gson? The gson library is standard supported for add-ons and can be used without additional dependencies in your binding.

Hi

Thanks for the quick reply.
I’ll try gson, it just that I was not aware of it.
But still, I want to know how to add other dependencies. I tried adding to feature.xml like this (in source/main/feature).

    <feature name="openhab-binding-met" description="MET Binding" version="${project.version}">
        <feature>openhab-runtime-base</feature>
        <bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.met/${project.version}</bundle>
        <bundle dependency="true">mvn:com.jayway.jsonpath/json-path/2.4.0</bundle>
    </feature>

Is that the correct way? Didn’t seem to make any difference.

The specific error message is this:

What it can’t find I’ve put in bold. This seems a library used by jsonpath. All libraries needed, including dependent libraries, must be added to the feature.xml file.

After adding a handful of dependencies it finally compiled.Thanks for pointing me in the right direction.

Btw, I will use gson instead as you suggested (I noticed its mentioned in the code guideline as well :slight_smile: )