A strange maven error when building my binding

Hi all, I created a new binding, and it can be built severaly days before. But today when I tried to build it with mvn clean install, a strange error happened, which is shown as below.

[ERROR] Failed to execute goal org.apache.karaf.tooling:karaf-maven-plugin:4.2.7:verify (karaf-feature-verification) on project org.openhab.binding.mylogger: Feature resolution failed for [openhab-binding-mylogger/2.5.0.SNAPSHOT]

Message: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=openhab-binding-mylogger; type=karaf.feature; version=2.5.0.SNAPSHOT; filter:=“(&(osgi.identity=openhab-binding-mylogger)(type=karaf.feature)(version>=2.5.0.SNAPSHOT))” [caused by: Unable to resolve openhab-binding-mylogger/2.5.0.SNAPSHOT: missing requirement [openhab-binding-mylogger/2.5.0.SNAPSHOT] osgi.identity; osgi.identity=org.openhab.binding.mylogger; type=osgi.bundle; version=“[2.5.0.202001041605,2.5.0.202001041605]”; resolution:=mandatory [caused by: Unable to resolve org.openhab.binding.mylogger/2.5.0.202001041605: missing requirement [org.openhab.binding.mylogger/2.5.0.202001041605] osgi.wiring.package; filter:=“(osgi.wiring.package=org.openhab.core.automation)”]]

I actually implemented a component, which is used for outputing all rules. Here is my code.

@NonNullByDefault
@Component(immediate = true)
public class RuleCapture {

private @NonNullByDefault({}) RuleRegistry Ruleservice;

private final Logger logger = LoggerFactory.getLogger(RuleCapture.class);

@Reference
public void setService(RuleRegistry Ruleservice) {
    this.Ruleservice = Ruleservice;
}

@Activate
public void activate(BundleContext context) {
    getAllRules();
}

public void getAllRules() {
    Collection<Rule> rules = Ruleservice.getAll();
    logger.info("The size is {}", rules.size());
    for (Rule rule : rules) {
        logger.info("Current rule UID: {} name: {} tag: {} Description: {}", rule.getUID(), rule.getName(),
                rule.getTags(), rule.getDescription());
    }
    /* For further exploration of rules, please refer to the Rule interface. */
}

}

To do that, I need to import some packages, which are related to org.openhab.core.automation.

import org.openhab.core.automation.Rule;

import org.openhab.core.automation.RuleRegistry;

However it can be built several days before, today it can not be built and the error messages seem to tell me that, the karaf-maven-plugin tries to verify the automation component, but it can not find it. I didn’t import any core component in my current workspace, because I thought the openhab internal pom files and maven will help me do this automatically. What happened? Can anyone tell me? I don’t know how to solve it.

There is no more 2.5.0 snapshot. I think there is a 2.5.1 snapshot.

So should I modify something? However when I tried to build the original openhab binding, like icloud binding, the build information still notifies 2.5.0-SNAPSHOT

I have just seen that error here. A search in the Development part of the forum should have the answer.

We’re here Bruce. :wink:

@Jony - your binding depends on extra things which are not declared in feature descriptor. The error message looks creepy but in fact it explains everything step by step. Lets take a look on it.

During the build a resolution attempt of your feature called openhab-binding-mylogger was made. The dependency resolver spotted an error which is chained in following way:

  1. Resolution of feature openhab-binding-mylogger failed because of missing requirement.
  2. Bundle with symbolic name org.openhab.binding.mylogger failed to resolve due to missing mandatory requirement.
  3. The necessary requirement is presence of org.openhab.core.automation package.

As we know what the error is we can proceed to solution, which is not that difficult. Most likely you have in your feature something like this:

  <feature name="openhab-binding-mylogger" ...>
    <feature>openhab-runtime-base</feature>
   ...
  </feature>

The problem is that org.openhab.core.automation package is not supplied by core runtime (out of the box). It is an additional feature which needs to be placed into your feature descriptor.

Please swap the openhab-runtime-base with openhab-core-automation. It will bring runtime base + ephemeris service + automation core.

Hope that this helps,
Cheers,
Ɓukasz

2 Likes

Hi Splatch, first thank you so much that you solved my problem! But there are four questions which confuses me all the time.

  1. How do you know that openhab-runtime-base does not contain the openhab-core-automation? Where do you learn the truth, or how can I learn it?
  2. Previously I never changed the feature.xml, but it can still be built successfuly. What does that happen?
  3. In Eclipse, when we use demo.app to test a binding, I see that Felix + gogo shell is running. I think Felix is an OSGI container, however Karaf is also an OSGI container. Why do we still need to execute karaf-verify goal in Eclipse? I think in Eclipse, we don’t use Karaf for test. I guess the reason is that by passing karaf-verify goal, one can make sure his binding can be used directly when jumping out of Eclipse test, to the release version. Is the understanding correct? :slight_smile:
  4. The openhab is built based on bnd. However when I follow the Bndtools tutorial ( because I need to learn it in advance), I see that there is always a bnd.bnd file for each bundle. However, in openHAB I didn’t see bnd.bnd files for most bundles. What happened?

Sorry that I may have a weak OSGI programming foundation. I hope you could help me answer these 4 questions, such that I can get a better understanding. Thank you so much again!

I’m glad you was able to move forward, here are additional answers for what confused you:

I used openhab-core feature file to determine how automation package goes into runtime. You can verify that here: openhab-core/features/karaf/openhab-core/src/main/feature/feature.xml at 2.5.0 · openhab/openhab-core · GitHub. If you are interested in understanding semantics of this file you can read about Apache Karaf Provisioning.

You haven’t had to modify it since you was doing regular binding development which is based on default runtime. You can however have a cases where your binding is based on modbus transport or contribute to discovery of modbus enabled devices thus depending on presence of the modbus APIs. This is situation where you need to amend your feature definitions.

Per say Karaf is not an OSGi container as it requires Felix framework as well. It is a layer above framework assembling some useful utilities such console, logging, provisioning (feature files), configuration handling and common functionalities. Given the diversity of OSGi ecosystem it saves you time on preparing environment for application execution.
I think demo.bnd launches framework and console alone without Karaf specific extensions. I do not use bnd tools thus can’t say that for sure.
You are right that the execution of karaf-verify goal is added for safety reasons. If verification passes then your feature set is consistent with specified runtime conditions and will guarantee bundle resolution. It is worth to note that feature might define particular versions of dependencies which will bind it to ie. openhab 2.4 or 2.5. Answering your question - yes, your understanding is correct.

openHAB build is made in a way that bnd defaults are passed to underlying modules. If you inherit your settings from openhab bundles/addons2 pom (your maven parent is one of these), then all the setup is made for you out of the box.

OSGi universe is divided into multiple constellations (bndtools, eclipse foundation/tycho, karaf, maven) which do same things in a different way making it really hard to navigate. I hope that above answers will help you getting through the beginnings.

Cheers,
Ɓukasz

2 Likes