Unresolved requirement: Import-Package: org.slf4j; version="[2.0.0,3.0.0)"

Hi, although I have been using openHAB for about 3 years until recently I had not coded in Java.
I am trying to develop a binding but have stumbled on an issue that has my stumped and was hoping for some help.

I have followed these guides:

Java:

java 17.0.10 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 17.0.10+11-LTS-240)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.10+11-LTS-240, mixed mode, sharing)

And have an openHAB 4.0.4 development environment set up on a Windows 10 machine.
I took a copy of the openhab-addons about six weeks ago using:

git clone https://github.com/openhab/openhab-addons.git

and this is where my I have be writing my binding.

I am able to compile the binding and produce the .jar, but am unable to progress to testing as when I try to debug the binding, I get the following in the openHAB.log:

2024-03-10 16:55:02.618 [INFO ] [org.openhab.core.Activator          ] - Starting openHAB 4.0.4 (build Release Build)
2024-03-10 16:55:03.594 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Time zone set to 'Europe/London'.
2024-03-10 16:55:03.607 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Location set to '51.03343985855335,-2.2592890262603764'.
2024-03-10 16:55:03.609 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Locale set to 'en_GB'.
2024-03-10 16:55:10.169 [WARN ] [org.openhab.core.net.NetUtil        ] - Found multiple local interfaces - ignoring 192.168.1.197
2024-03-10 16:55:19.791 [INFO ] [.core.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2024-03-10 16:55:24.433 [ERROR] [Events.Framework                    ] - FrameworkEvent ERROR
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.sunsynk [241]
  Unresolved requirement: Import-Package: org.slf4j; version="[2.0.0,3.0.0)"

	at org.eclipse.osgi.container.Module.start(Module.java:463) ~[org.eclipse.osgi-3.18.0.jar:?]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel$2.run(ModuleContainer.java:1847) ~[org.eclipse.osgi-3.18.0.jar:?]
	at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor$1$1.execute(EquinoxContainerAdaptor.java:136) ~[org.eclipse.osgi-3.18.0.jar:?]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1840) ~[org.eclipse.osgi-3.18.0.jar:?]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1783) ~[org.eclipse.osgi-3.18.0.jar:?]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1745) ~[org.eclipse.osgi-3.18.0.jar:?]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1667) ~[org.eclipse.osgi-3.18.0.jar:?]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1) ~[org.eclipse.osgi-3.18.0.jar:?]
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:234) ~[org.eclipse.osgi-3.18.0.jar:?]
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:345) ~[org.eclipse.osgi-3.18.0.jar:?]

I manged to resolve what feels like a similar problem by following this discussion: Problem dependencies

Similar problem was:

org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.sunsynk [241]
  Unresolved requirement: Import-Package: com.google.gson; version="[2.10.0,3.0.0)"

Resolution was to use the karaf console and install the missing dependency:

bundle:install https://repo1.maven.org/maven2/com/google/code/gson/gson/2.10/gson-2.10.jar

However I have not been able to fix:

Unresolved requirement: Import-Package: org.slf4j; version="[2.0.0,3.0.0)"

Having Googled around I have tried various things including this in Karaf console:

bundle:install https://repo1.maven.org/maven2/org/slf4j/slf4j-api/2.0.0/slf4j-api-2.0.0.jar
bundle:install https://repo1.maven.org/maven2/org/slf4j/osgi-over-slf4j/2.0.0/osgi-over-slf4j-2.0.0.jar

I have also rebuild one of the known working bindings in the cloned addons, but exactly the same issue when I try to debug.

Maybe I am missing something obvious?
To be honest my novice skills in Java maybe holding me back, not sure I fully understand dependency management, Maven and pom.xml well.

Any help appreciated.

Problem is - your runtime already have org.slf4j package, but in different version. Instead of bringing upper version of slf4j it is better to verify where difference comes from.

Take a look on your pom.xml and make sure you do not define version for slf4j-api artifact, it should be inherited and available within classpath for use. You can use other versions of artifacts, but then they should be used only under src/test/java and declared using <scope>test</scope>.

Most of dependencies needed to develop stuff can be inherited from openhab-addons pom. You can also try to use externalized BOM (GitHub - thingfour/openhab-bom: Generated Bill Of Materials (BOM) files for openHAB project.) which I were made for re-use for third party development.

Thanks splatch

My POM is pretty sparse, just the defaults from the command

./create_openhab_binding_skeleton.sh  MyNewBinding "<Author>" <GitHubUsername>

I have searched under my binding location org.openhab.binding.sunsynk and there is only one POM:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.openhab.addons.bundles</groupId>
    <artifactId>org.openhab.addons.reactor.bundles</artifactId>
    <version>4.2.0-SNAPSHOT</version>
  </parent>

  <artifactId>org.openhab.binding.sunsynk</artifactId>

  <name>openHAB Add-ons :: Bundles :: SunSynk Binding</name>

</project>

Should I be looking somewhere else?
I also searched for org.slf4j from the same point and the only hits I got were those at the tops of my .java files.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

I followed your link about the BOM, to be honest I didn’t fully understand, but I placed this in my POM:
with < !-- place openHAB version here – > replaced with 4.0.4 the version of my openHAB installation.

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>org.thing4.openhab.bom.generated</groupId>
          <artifactId>org.openhab.core.bom.openhab-core</artifactId>
          <version><!-- place openHAB version here --></version>
          <type>pom</type>
          <scope>import</scope>
        </dependency>
      </dependencies>
    </dependencyManagement>

Recompiled, but still the same:

2024-03-11 18:28:14.333 [INFO ] [org.openhab.core.Activator          ] - Starting openHAB 4.0.4 (build Release Build)
2024-03-11 18:28:15.487 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Time zone set to 'Europe/London'.
2024-03-11 18:28:15.510 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Location set to '51.03343985855335,-2.2592890262603764'.
2024-03-11 18:28:15.511 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Locale set to 'en_GB'.
2024-03-11 18:28:19.996 [WARN ] [org.openhab.core.net.NetUtil        ] - Found multiple local interfaces - ignoring 192.168.1.197
2024-03-11 18:28:28.842 [INFO ] [.core.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2024-03-11 18:28:32.907 [ERROR] [Events.Framework                    ] - FrameworkEvent ERROR
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.neato [247]
  Unresolved requirement: Import-Package: org.slf4j; version="[2.0.0,3.0.0)"

        at org.eclipse.osgi.container.Module.start(Module.java:463) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel$2.run(ModuleContainer.java:1847) ~[org.eclipse.osgi-3.18.0.jar:?]  
        at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor$1$1.execute(EquinoxContainerAdaptor.java:136) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1840) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1783) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1745) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1667) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:234) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:345) ~[org.eclipse.osgi-3.18.0.jar:?]
2024-03-11 18:28:32.919 [ERROR] [Events.Framework                    ] - FrameworkEvent ERROR
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.sunsynk [248]
  Unresolved requirement: Import-Package: org.slf4j; version="[2.0.0,3.0.0)"

        at org.eclipse.osgi.container.Module.start(Module.java:463) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel$2.run(ModuleContainer.java:1847) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor$1$1.execute(EquinoxContainerAdaptor.java:136) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1840) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1783) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1745) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1667) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:234) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:345) ~[org.eclipse.osgi-3.18.0.jar:?]
2024-03-11 18:28:36.128 [INFO ] [e.automation.internal.RuleEngineImpl] - Rule engine started.
2024-03-11 18:28:48.354 [WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/C:/openHAB/addons/org.openhab.binding.sunsynk-4.2.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.sunsynk [248]
  Unresolved requirement: Import-Package: org.slf4j; version="[2.0.0,3.0.0)"

        at org.eclipse.osgi.container.Module.start(Module.java:463) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:445) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) ~[?:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) ~[?:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1221) ~[?:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:515) ~[?:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) ~[?:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) ~[?:?]
2024-03-11 18:28:48.366 [WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/C:/openHAB/addons/org.openhab.binding.sunsynk-4.2.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.sunsynk [248]
  Unresolved requirement: Import-Package: org.slf4j; version="[2.0.0,3.0.0)"

        at org.eclipse.osgi.container.Module.start(Module.java:463) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:445) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) ~[?:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) ~[?:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:520) ~[?:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) ~[?:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) ~[?:?]

Have I done this correctly?

I didn’t understand this.

If you started with OH scaffold stuff stay with it. BUT your addon parent points to openHAB 4.2.0-SNAPSHOT. If you compile against this version you should probably run this OH version too. I suppose you are testing binding with OH 4.1.x, or I am wrong? If you test with OH 4.1.x runtime change your addon parent version to that version.

Thanks Splatch.

In case it helps anyone else, I updated my openHAB version for testing (installed openHAB) to the latest 4.2.0.M1 as suggested.
So the addons directory 4.2.0-SNAPSHOT is sufficiently similar for the dependencies to be the same and for my binding to start.
I reverted my POM to that listed in the above post as created by the command:

./create_openhab_binding_skeleton.sh  MyNewBinding "<Author>" <GitHubUsername>

Now just to resolve all the functional issue :slight_smile:

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.