New binding build fails when targeting old openHAB version

I started developing my own binding for openHAB in a fork of the addons repo which is for version 5.0.0 if I understood correctly.

I intend to deploy it onto openHAB 4.1.3 as it is the one I have running at home and I do not have the need to upgrade right now. Therefore I used the -Dohc.version=4.1.3 to target the correct version of openHAB.

My instance runs on OpenJDK 17 so I used the maven profile -Pj17.

This compilation fails during the karaf-feature-verify because the versions are mismatched:

[ERROR] Failed to execute goal org.apache.karaf.tooling:karaf-maven-plugin:4.4.7:verify (karaf-feature-verification) on project org.openhab.binding.energymanager: Feature resolution failed for [openhab-binding-energymanager/5.0.0.SNAPSHOT]
[ERROR] Message: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=openhab-binding-energymanager; type=karaf.feature; version=5.0.0.SNAPSHOT; filter:="(&(osgi.identity=openhab-binding-energymanager)(type=karaf.feature)(version>=5.0.0.SNAPSHOT))" [caused by: Unable to resolve openhab-binding-energymanager/5.0.0.SNAPSHOT: missing requirement [openhab-binding-energymanager/5.0.0.SNAPSHOT] osgi.identity; osgi.identity=openhab-runtime-base; type=karaf.feature [caused by: Unable to resolve openhab-runtime-base/4.1.3: missing requirement [openhab-runtime-base/4.1.3] osgi.identity; osgi.identity=openhab-core-model-item; type=karaf.feature [caused by: Unable to resolve openhab-core-model-item/4.1.3: missing requirement [openhab-core-model-item/4.1.3] osgi.identity; osgi.identity=org.openhab.core.model.item; type=osgi.bundle; version="[4.1.3,4.1.3]"; resolution:=mandatory [caused by: Unable to resolve org.openhab.core.model.item/4.1.3: missing requirement [org.openhab.core.model.item/4.1.3] osgi.wiring.bundle; osgi.wiring.bundle=org.eclipse.xtext.common.types; filter:="(osgi.wiring.bundle=org.eclipse.xtext.common.types)" [caused by: Unable to resolve org.eclipse.xtext.common.types/2.32.0.v20230827-1315: missing requirement [org.eclipse.xtext.common.types/2.32.0.v20230827-1315] osgi.wiring.bundle; osgi.wiring.bundle=org.objectweb.asm; bundle-version="[9.5.0,9.6.0)"; filter:="(&(osgi.wiring.bundle=org.objectweb.asm)(bundle-version>=9.5.0)(!(bundle-version>=9.6.0)))"]]]]]

I have no idea what caused this as I am very new to OSGi and Karaf, but googling got me to the cause being mismatched karaf versions so I tried running it with the Karaf version which openHAB 4.1.3 uses using this parameter -Dkaraf.version=4.4.4.

Using this results in a successful build of the binding, but is this the correct approach?

The binding is in it’s infancy (it does not even have a README yet) and won’t see the upstream for some time, but if you’re curious it’s here.

OH v4.3.x requires Java 17 whereas v5.x requires Java 21

Yes, that is why I used the -Pj17 profile.

Ok. I have no other suggestions.

Behavior of karaf feature validation may vary depending on many aspects, sometimes specific relationships may cause plugin to fail. These are addressed usually only in later versions when resolver algorithm is tweaked.
In your example your binding depends on openhab-runtime-base which is resolved when you launch openHAB. Thus this error can be ignored, and the way you skip it is fine.

If you will split error generated by karaf tooling plugin, you will see below tree:

missing osgi.identity=openhab-binding-energymanager; type=karaf.feature; version=5.0.0.SNAPSHOT; 
	[caused by: Unable to resolve openhab-binding-energymanager/5.0.0.SNAPSHOT: 
		missing requirement osgi.identity=openhab-runtime-base; type=karaf.feature
		[caused by: Unable to resolve openhab-runtime-base/4.1.3:
			missing requirement osgi.identity=openhab-core-model-item; type=karaf.feature 
			[caused by: Unable to resolve openhab-core-model-item/4.1.3:
				missing requirement osgi.identity=org.openhab.core.model.item; type=osgi.bundle; version="[4.1.3,4.1.3]"; resolution:=mandatory 
				[caused by: Unable to resolve org.openhab.core.model.item/4.1.3:
					missing requirement osgi.wiring.bundle; osgi.wiring.bundle=org.eclipse.xtext.common.types
					[caused by: Unable to resolve org.eclipse.xtext.common.types/2.32.0.v20230827-1315:
						missing requirement osgi.wiring.bundle; osgi.wiring.bundle=org.objectweb.asm; bundle-version="[9.5.0,9.6.0)";

And in human language it is:

  • Can’t resolve feature openhab-binding-energymanager
    • Because can’t resolve feature openhab-runtime-base
      • Because can’t resolve feature openhab-core-model-item
        • Because can’t resolve bundle org.openhab.core.model.item
          • Because can’t resolve bundle org.eclipse.xtext.common.types
            • Because bundle org.objectweb.asm is not found in specific version.

I’d call this error a false alarm, cause we know it works, and spins every day for these who run OH 4.x.

Best,
Ɓukasz

Ɓukasz, thank you for your in-depth reply.

The binding works once I bundle it into openHAB through the karaf console.

I wanted to know if this was the correct way to approach the build process for older versions and my workaround does not cause issues which manifest in runtime due to failing resolution of packages etc. This is my first time using Karaf and OSGi so it may seem like a trivial question.

From your answer I get that it should not cause issues, as the problem was unresolved openhab-runtime-base which is correctly resolved once i provide the correct version of Karaf with -Dkaraf.version. Did I understand you correctly?

Your way of dealing with issue is fine. The resolver failure is not related to your code.
In a way, as long as your addon resolves itself, it should be OK cause openhab-runtime-base it is a platform feature which is always going to be present in OH distro.

1 Like

Here’s what I think you should do:

  • check out 4.1.x branch
  • create a new branch based on it
  • cherry pick your main feature branch

I thought of doing that at first but it seemed rather counterintuitive, given that there are provided profiles to compile for specific ohc and java version.

Okay, thank you.
Should I create an issue about this in the addons github or is this expected behaviour?
Or is it something already addressed as you are mentioning here?

From my point of view as someone new to the codebase, I would expect the -Dohc.version which specifies the core version to have an effect on the resolution of the correct openhab-runtime-base package as well.