Optional dependency not available

For a DBQuery addon, I have optional dependencies with jdbc drivers in the same way the jdbc persistence add-on does.

This works correctly in my local dev instance that is downloaded from nightly builds but not in my ‘production’ instance that is running 3.2M2.

The problem is that my addon is loaded and activated correctly, but the optional dependency for PostgreSQL isn’t enabled for the addon, despite it’s present and with the correct version:

Result of bundle:headers on the addon:

But the PostgreSQL is correctly installed:

and extract from bundle:headers for the postgresql driver:

openhab> bundle:headers 279

PostgreSQL JDBC Driver (279)
----------------------------
Automatic-Module-Name = org.postgresql.jdbc
Implementation-Title = PostgreSQL JDBC Driver
Implementation-Vendor = PostgreSQL Global Development Group
Implementation-Vendor-Id = org.postgresql
Implementation-Version = 42.2.18
Main-Class = org.postgresql.util.PGJDBCMain
Manifest-Version = 1.0
Specification-Title = JDBC
Specification-Vendor = Oracle Corporation
Specification-Version = 4.2
Tool = Bnd-4.3.1.201911131708

Bundle-Activator = org.postgresql.osgi.PGBundleActivator
Bundle-Copyright = Copyright (c) 2003-2020, PostgreSQL Global Development Group
Bundle-Descriptiona = Java JDBC driver for PostgreSQL database
Bundle-DocURL = https://jdbc.postgresql.org/
Bundle-License = BSD-2-Clause
Bundle-ManifestVersion = 2
Bundle-Name = PostgreSQL JDBC Driver
Bundle-SymbolicName = org.postgresql.jdbc
Bundle-Vendor = PostgreSQL Global Development Group
Bundle-Version = 42.2.18

Provide-Capability =
        osgi.service;effective:=active;objectClass=org.osgi.service.jdbc.DataSourceFactory
Require-Capability =
        osgi.ee;filter:=(&(|(osgi.ee=J2SE)(osgi.ee=JavaSE))(version>=1.8))

Export-Package =
        org.postgresql;

The curious is that the same works in my dev machine.

Any help or advice to diagnose and find a solution will be appreciated.

What is the result of diag on the dbquery bundle?

The result from bundle:diag is blank, because the addon starts correctly because the driver is an optional dependency. The problem is that it’s not available in the classpath to establish a connection to de database.

What I’ve tried is to remove the optional and then that’s the output from diag:

openHAB Add-ons :: Bundles :: DBQuery Binding (278)
---------------------------------------------------
Status: Installed
Unsatisfied Requirements:
osgi.wiring.package; filter:="(&(osgi.wiring.package=com.mysql.jdbc)(&(version>=8.0.0)(!(version>=9.0.0))))"; resolution:="optional"
osgi.wiring.package; filter:="(&(osgi.wiring.package=org.h2)(&(version>=1.4.0)(!(version>=2.0.0))))"; resolution:="optional"
osgi.wiring.package; filter:="(&(osgi.wiring.package=org.h2.jdbcx)(&(version>=1.4.0)(!(version>=2.0.0))))"; resolution:="optional"
osgi.wiring.package; filter:="(osgi.wiring.package=org.hsqldb)"; resolution:="optional"
osgi.wiring.package; filter:="(osgi.wiring.package=org.hsqldb.jdbc)"; resolution:="optional"
osgi.wiring.package; filter:="(osgi.wiring.package=org.mariadb.jdbc)"; resolution:="optional"
osgi.wiring.package; filter:="(&(osgi.wiring.package=org.postgresql)(&(version>=42.2.0)(!(version>=43.0.0))))"
osgi.wiring.package; filter:="(&(osgi.wiring.package=org.sqlite)(&(version>=3.16.0)(!(version>=4.0.0))))"; resolution:="optional"
osgi.wiring.package; filter:="(&(osgi.wiring.package=org.sqlite.jdbc4)(&(version>=3.16.0)(!(version>=4.0.0))))"; resolution:="optional"
Declarative Services

But I still don’t know why it isn’t satisfied by the PostgreSQL driver that it’s already available with that:

openhab> bundle:headers 279

PostgreSQL JDBC Driver (279)
----------------------------
Automatic-Module-Name = org.postgresql.jdbc
Implementation-Title = PostgreSQL JDBC Driver
Implementation-Vendor = PostgreSQL Global Development Group
Implementation-Vendor-Id = org.postgresql
Implementation-Version = 42.2.18
Main-Class = org.postgresql.util.PGJDBCMain
Manifest-Version = 1.0
Specification-Title = JDBC
Specification-Vendor = Oracle Corporation
Specification-Version = 4.2
Tool = Bnd-4.3.1.201911131708

Bundle-Activator = org.postgresql.osgi.PGBundleActivator
Bundle-Copyright = Copyright (c) 2003-2020, PostgreSQL Global Development Group
Bundle-Descriptiona = Java JDBC driver for PostgreSQL database
Bundle-DocURL = https://jdbc.postgresql.org/
Bundle-License = BSD-2-Clause
Bundle-ManifestVersion = 2
Bundle-Name = PostgreSQL JDBC Driver
Bundle-SymbolicName = org.postgresql.jdbc
Bundle-Vendor = PostgreSQL Global Development Group
Bundle-Version = 42.2.18

Provide-Capability =
        osgi.service;effective:=active;objectClass=org.osgi.service.jdbc.DataSourceFactory
Require-Capability =
        osgi.ee;filter:=(&(|(osgi.ee=J2SE)(osgi.ee=JavaSE))(version>=1.8))

Export-Package =
        org.postgresql;
                uses:="org.checkerframework.checker.nullness.qual,
                        org.postgresql.copy,
                        org.postgresql.fastpath,
                        org.postgresql.jdbc,
                        org.postgresql.largeobject,
                        org.postgresql.replication,
                        org.postgresql.util";
                version=42.2.18,
        org.postgresql.copy;
                uses:="org.checkerframework.checker.nullness.qual,
                        org.postgresql,
                        org.postgresql.core,
                        org.postgresql.util";
                version=42.2.18,
        org.postgresql.core;
                uses:="javax.net,
                        javax.net.ssl,
                        org.checkerframework.checker.index.qual,
                        org.checkerframework.checker.nullness.qual,
                        org.checkerframework.dataflow.qual,
                        org.ietf.jgss,
                        org.postgresql,
                        org.postgresql.copy,
                        org.postgresql.core.v3,
                        org.postgresql.jdbc,
                        org.postgresql.replication,
                        org.postgresql.replication.fluent.logical,
                        org.postgresql.replication.fluent.physical,
                        org.postgresql.util,
                        org.postgresql.xml";
                version=42.2.18,
        org.postgresql.core.v3;
                uses:="org.checkerframework.checker.nullness.qual,
                        org.postgresql.copy,
                        org.postgresql.core,
                        org.postgresql.jdbc,
                        org.postgresql.util";
                version=42.2.18,
        org.postgresql.core.v3.replication;
                uses:="org.checkerframework.checker.nullness.qual,
                        org.postgresql.copy,
                        org.postgresql.core,
                        org.postgresql.replication,
                        org.postgresql.replication.fluent.logical,
                        org.postgresql.replication.fluent.physical";
                version=42.2.18,
        org.postgresql.ds;
                uses:="javax.naming,
                        javax.sql,
                        org.checkerframework.checker.nullness.qual,
                        org.postgresql.ds.common";
                version=42.2.18,
        org.postgresql.ds.common;
                uses:="javax.naming,
                        javax.naming.spi,
                        javax.sql,
                        org.checkerframework.checker.nullness.qual,
                        org.postgresql,
                        org.postgresql.jdbc";
                version=42.2.18,
        org.postgresql.fastpath;uses:="org.checkerframework.checker.nullness.qual,org.postgresql.core";version=42.2.18,
        org.postgresql.geometric;uses:="org.checkerframework.checker.nullness.qual,org.postgresql.util";version=42.2.18,
        org.postgresql.gss;
                uses:="javax.security.auth.callback,
                        org.checkerframework.checker.nullness.qual,
                        org.ietf.jgss,
                        org.postgresql.core,
                        org.postgresql.util";
                version=42.2.18,
        org.postgresql.hostchooser;uses:="org.checkerframework.checker.nullness.qual,org.postgresql.util";version=42.2.18,
        org.postgresql.jdbc;
                uses:="javax.xml.transform,
                        org.checkerframework.checker.index.qual,
                        org.checkerframework.checker.lock.qual,
                        org.checkerframework.checker.nullness.qual,
                        org.checkerframework.dataflow.qual,
                        org.postgresql,
                        org.postgresql.copy,
                        org.postgresql.core,
                        org.postgresql.fastpath,
                        org.postgresql.jdbc2,
                        org.postgresql.largeobject,
                        org.postgresql.replication,
                        org.postgresql.util,
                        org.postgresql.xml";
                version=42.2.18,
        org.postgresql.jdbc2;uses:=org.checkerframework.checker.nullness.qual;version=42.2.18,
        org.postgresql.jdbc2.optional;uses:=org.postgresql.ds;version=42.2.18,
        org.postgresql.jdbc3;uses:=org.postgresql.ds;version=42.2.18,
        org.postgresql.jre7.sasl;uses:="org.postgresql.core,org.postgresql.util";version=42.2.18,
        org.postgresql.largeobject;
                uses:="org.checkerframework.checker.nullness.qual,
                        org.postgresql.core,
                        org.postgresql.fastpath";
                version=42.2.18,
        org.postgresql.osgi;uses:="javax.sql,org.osgi.framework,org.osgi.service.jdbc";version=42.2.18,
        org.postgresql.replication;
                uses:="org.checkerframework.checker.nullness.qual,
                        org.postgresql.core,
                        org.postgresql.replication.fluent";
                version=42.2.18,
        org.postgresql.replication.fluent;
                uses:="org.checkerframework.checker.nullness.qual,
                        org.postgresql.core,
                        org.postgresql.replication,
                        org.postgresql.replication.fluent.logical,
                        org.postgresql.replication.fluent.physical";
                version=42.2.18,
        org.postgresql.replication.fluent.logical;
                uses:="org.checkerframework.checker.nullness.qual,
                        org.postgresql.core,
                        org.postgresql.replication,
                        org.postgresql.replication.fluent";
                version=42.2.18,
        org.postgresql.replication.fluent.physical;
                uses:="org.checkerframework.checker.nullness.qual,
                        org.postgresql.core,
                        org.postgresql.replication,
                        org.postgresql.replication.fluent";
                version=42.2.18,
        org.postgresql.ssl;
                uses:="javax.net.ssl,
                        javax.security.auth.callback,
                        org.checkerframework.checker.nullness.qual,
                        org.postgresql.core,
                        org.postgresql.util";
                version=42.2.18,
        org.postgresql.ssl.jdbc4;uses:="javax.net.ssl,org.postgresql.ssl,org.postgresql.util";version=42.2.18,
        org.postgresql.sspi;uses:="com.sun.jna,org.checkerframework.checker.nullness.qual,org.postgresql.core";version=42.2.18,
        org.postgresql.translation;version=42.2.18,
        org.postgresql.util;
                uses:="org.checkerframework.checker.nullness.qual,
                        org.checkerframework.dataflow.qual,
                        org.postgresql.core";
                version=42.2.18,
        org.postgresql.util.internal;
                uses:="org.checkerframework.checker.nullness.qual,
                        org.checkerframework.dataflow.qual";
                version=42.2.18,
        org.postgresql.xa;
                uses:="javax.naming,
                        javax.sql,
                        javax.transaction.xa,
                        org.checkerframework.checker.nullness.qual,
                        org.postgresql.core,
                        org.postgresql.ds,
                        org.postgresql.ds.common";
                version=42.2.18,
        org.postgresql.xml;
                uses:="javax.xml.parsers,
                        javax.xml.stream,
                        javax.xml.transform,
                        javax.xml.transform.sax,
                        org.checkerframework.checker.nullness.qual,
                        org.xml.sax";
                version=42.2.18
Import-Package =
        javax.sql,
        javax.transaction.xa,
        javax.naming,
        javax.security.sasl;resolution:=optional,
        com.sun.jna;resolution:=optional,
        com.sun.jna.platform.win32;resolution:=optional,
        com.sun.jna.ptr;resolution:=optional,
        com.sun.jna.win32;resolution:=optional,
        javax.crypto;resolution:=optional,
        javax.crypto.spec;resolution:=optional,
        javax.naming.ldap;resolution:=optional,
        javax.naming.spi;resolution:=optional,
        javax.net;resolution:=optional,
        javax.net.ssl;resolution:=optional,
        javax.security.auth;resolution:=optional,
        javax.security.auth.callback;resolution:=optional,
        javax.security.auth.login;resolution:=optional,
        javax.security.auth.x500;resolution:=optional,
        javax.xml.parsers;resolution:=optional,
        javax.xml.stream;resolution:=optional,
        javax.xml.transform;resolution:=optional,
        javax.xml.transform.dom;resolution:=optional,
        javax.xml.transform.sax;resolution:=optional,
        javax.xml.transform.stax;resolution:=optional,
        javax.xml.transform.stream;resolution:=optional,
        org.checkerframework.checker.index.qual;resolution:=optional;version="[3.5,4)",
        org.checkerframework.checker.initialization.qual;resolution:=optional;version="[3.5,4)",
        org.checkerframework.checker.lock.qual;resolution:=optional;version="[3.5,4)",
        org.checkerframework.checker.nullness.qual;resolution:=optional;version="[3.5,4)",
        org.checkerframework.checker.regex.qual;resolution:=optional;version="[3.5,4)",
        org.checkerframework.common.value.qual;resolution:=optional;version="[3.5,4)",
        org.checkerframework.dataflow.qual;resolution:=optional;version="[3.5,4)",
        org.checkerframework.framework.qual;resolution:=optional;version="[3.5,4)",
        org.ietf.jgss;resolution:=optional,
        org.osgi.framework;resolution:=optional;version="[1.6,2)",
        org.osgi.service.jdbc;resolution:=optional;version="[1.0,2)",
        org.postgresql;resolution:=optional,
        org.postgresql.copy;resolution:=optional,
        org.postgresql.core;resolution:=optional,
        org.postgresql.core.v3;resolution:=optional,
        org.postgresql.core.v3.replication;resolution:=optional,
        org.postgresql.ds;resolution:=optional,
        org.postgresql.ds.common;resolution:=optional,
        org.postgresql.fastpath;resolution:=optional,
        org.postgresql.geometric;resolution:=optional,
        org.postgresql.gss;resolution:=optional,
        org.postgresql.hostchooser;resolution:=optional,
        org.postgresql.jdbc;resolution:=optional,
        org.postgresql.jdbc2;resolution:=optional,
        org.postgresql.jdbc2.optional;resolution:=optional,
        org.postgresql.largeobject;resolution:=optional,
        org.postgresql.replication;resolution:=optional,
        org.postgresql.replication.fluent;resolution:=optional,
        org.postgresql.replication.fluent.logical;resolution:=optional,
        org.postgresql.replication.fluent.physical;resolution:=optional,
        org.postgresql.ssl;resolution:=optional,
        org.postgresql.sspi;resolution:=optional,
        org.postgresql.util;resolution:=optional,
        org.postgresql.util.internal;resolution:=optional,
        org.postgresql.xa;resolution:=optional,
        org.postgresql.xml;resolution:=optional,
        org.w3c.dom;resolution:=optional,
        org.xml.sax;resolution:=optional,
        org.xml.sax.helpers;resolution:=optional,
        waffle.windows.auth;resolution:=optional,
        waffle.windows.auth.impl;resolution:=optional
Private-Package =
        org.postgresql.shaded.com.ongres.saslprep,
        org.postgresql.shaded.com.ongres.scram.client,
        org.postgresql.shaded.com.ongres.scram.common,
        org.postgresql.shaded.com.ongres.scram.common.bouncycastle.base64,
        org.postgresql.shaded.com.ongres.scram.common.bouncycastle.pbkdf2,
        org.postgresql.shaded.com.ongres.scram.common.exception,
        org.postgresql.shaded.com.ongres.scram.common.gssapi,
        org.postgresql.shaded.com.ongres.scram.common.message,
        org.postgresql.shaded.com.ongres.scram.common.stringprep,
        org.postgresql.shaded.com.ongres.scram.common.util,
        org.postgresql.shaded.com.ongres.stringprep

Maybe tree-show <bundlename> on both machines shows a difference.

Thanks @J-N-K , I tried, but I don’t see any relevant difference. There are some because one is a nighty build and another M2, and also for other installed addons but in what is relevant to me are equal.

It’s possible a silly mistake, but by now, I’m not able to see anything. It’s very strange the diag fails with the mandatory postgresql dependency, but it seems to be present:

openhab> bundle:diag 280
openHAB Add-ons :: Bundles :: DBQuery Binding (280)
---------------------------------------------------
Status: Installed
Unsatisfied Requirements:
osgi.wiring.package; filter:="(&(osgi.wiring.package=com.mysql.jdbc)(&(version>=8.0.0)(!(version>=9.0.0))))"; resolution:="optional"
osgi.wiring.package; filter:="(&(osgi.wiring.package=org.h2)(&(version>=1.4.0)(!(version>=2.0.0))))"; resolution:="optional"
osgi.wiring.package; filter:="(&(osgi.wiring.package=org.h2.jdbcx)(&(version>=1.4.0)(!(version>=2.0.0))))"; resolution:="optional"
osgi.wiring.package; filter:="(osgi.wiring.package=org.hsqldb)"; resolution:="optional"
osgi.wiring.package; filter:="(osgi.wiring.package=org.hsqldb.jdbc)"; resolution:="optional"
osgi.wiring.package; filter:="(osgi.wiring.package=org.mariadb.jdbc)"; resolution:="optional"
osgi.wiring.package; filter:="(&(osgi.wiring.package=org.postgresql)(&(version>=42.2.0)(!(version>=43.0.0))))"
osgi.wiring.package; filter:="(&(osgi.wiring.package=org.sqlite)(&(version>=3.16.0)(!(version>=4.0.0))))"; resolution:="optional"
osgi.wiring.package; filter:="(&(osgi.wiring.package=org.sqlite.jdbc4)(&(version>=3.16.0)(!(version>=4.0.0))))"; resolution:="optional"
Declarative Services


openhab> bundle:list |grep -i postgresql
279 │ Active    │  80 │ 42.2.18               │ PostgreSQL JDBC Driver
openhab> exports |grep org.postgresql
org.postgresql.copy                                                    │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.core.v3.replication                                     │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.core.v3                                                 │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.core                                                    │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.ds.common                                               │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.ds                                                      │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.fastpath                                                │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.geometric                                               │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.gss                                                     │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.hostchooser                                             │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.jdbc2.optional                                          │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.jdbc2                                                   │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.jdbc3                                                   │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.jdbc                                                    │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.jre7.sasl                                               │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.largeobject                                             │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.osgi                                                    │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.replication.fluent.logical                              │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.replication.fluent.physical                             │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.replication.fluent                                      │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.replication                                             │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.ssl.jdbc4                                               │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.ssl                                                     │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.sspi                                                    │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.translation                                             │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.util.internal                                           │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.util                                                    │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.xa                                                      │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql.xml                                                     │ 42.2.18               │ 279 │ org.postgresql.jdbc
org.postgresql                                                         │ 42.2.18               │ 279 │ org.postgresql.jdbc

At the end uninstalling an installing again the postgresql dependency did the trick.
But I don’t know because I did the same way using bundle:install https://repo1.maven.org/maven2/org/postgresql/postgresql/42.2.18/postgresql-42.2.18.jar

1 Like