[SOLVED] Pin a dependency version in feature.xml

Trying to integrate a newer Version of ical4j i’m failing to get my bundle built as there is a missing dependency. The resolution of dependencies gives me a wiring error back to (&(osgi.wiring.package=net.fortuna.ical4j.data)(&(version>=3.0.0)(!(version>=4.0.0)))). From my understanding, the package net.fortuna.ical4j.data in 3.0.0 <= version < 4.0.0 is searched, which is not configured in the feature.xml:

<?xml version="1.0" encoding="UTF-8"?>
<features name="org.openhab.binding.icalpresence-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
    <repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${project.version}/xml/features</repository>
    
    <feature name="openhab-binding-icalpresence" description="iCalPresence Binding" version="${project.version}">
        <feature>openhab-runtime-base</feature>
        <bundle dependency="true">mvn:org.mnode.ical4j/ical4j/3.0.4</bundle>
        <bundle dependency="true">mvn:org.apache.commons/commons-lang3/3.9</bundle>
        <bundle dependency="true">mvn:javax.cache/cache-api/1.0.0</bundle>
        <bundle dependency="true">mvn:org.apache.commons/commons-collections4/4.1</bundle>
        <bundle dependency="true">mvn:javax.mail/javax.mail-api/1.6.2</bundle>
        <bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.icalpresence/${project.version}</bundle>
    </feature>
</features>

As the current version of ical4j does not export the dependencies properly, i’d like to pin the version until this issue is fixed. Is there a way to specify the exact version?

Which version is defined in the pom?

The same version and also the same versions of the dependencies. See for reference the pom:

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/maven-v4_0_0.xsd">

  <!-- [...] -->
  
  <dependencies>
    <!-- own dependencies -->
    <dependency>
       <groupId>org.mnode.ical4j</groupId>
       <artifactId>ical4j</artifactId>
       <version>3.0.4</version>
       <scope>provided</scope>
    </dependency>
    <!-- requirements by ical4j -->
    <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-lang3</artifactId>
       <version>3.9</version>
       <scope>provided</scope>
    </dependency>
    <dependency>
       <groupId>javax.cache</groupId>
       <artifactId>cache-api</artifactId>
       <version>1.0.0</version>
       <scope>provided</scope>
    </dependency>
    <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-collections4</artifactId>
       <version>4.1</version>
       <scope>provided</scope>
    </dependency>
    <!-- CDDL! -->
    <dependency>
       <groupId>javax.mail</groupId>
       <artifactId>javax.mail-api</artifactId>
       <version>1.6.2</version>
       <scope>provided</scope>
    </dependency>
  </dependencies>
</project>

However there are also newer versions of some dependencies available where ping may be necessary in case of trouble. I’ve also writen a small test for the logic, there (in my understanding) the dependencies defined in the pom should be used.

I assume from that behavior i should use always same versions in feature.xml and pom.xml. Is this assumption wrong?

Are you sure that one of the bundles really exports that package? I think that is the problem, because 3.0.4 is in the range mentioned above. Maybe you need to add another bundle to the feature.

hmm. I also thought about that problem. Looking into the META-INF/MANIFEST.MF inside ical4j.jar, i would say yes it does:

Manifest-Version: 1.0
Export-Package: net.fortuna.ical4j.agent;version="3.0.4";uses:="net.fo
 rtuna.ical4j.model,net.fortuna.ical4j.model.component,net.fortuna.ica
 l4j.model.property,net.fortuna.ical4j.util",net.fortuna.ical4j.data;v
 ersion="3.0.4";uses:="net.fortuna.ical4j.model,net.fortuna.ical4j.mod
 el.component,net.fortuna.ical4j.validate", [...]
Bundle-SymbolicName: org.mnode.ical4j
Bundle-Version: 3.0.4
Bundle-Name: ical4j
Bundle-ManifestVersion: 2
Bnd-LastModified: 1544925820000
Import-Package: [...]
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Created-By: 1.8.0_151 (Oracle Corporation)
Tool: Bnd-3.4.0.201707252008

In this case i wanted to pin this library as the following version had problems with the exported list. However the author Ben Fortuna has fixed it already/will fix it at next release (a Big Thank You, Mr. Fortuna!). But the library is still using specific versions of other libraries.

I have also looked up all the dependencies - but have nothing found required further. Do have another ideas how to solve?

The solution for this is in following topic:

Dependencies should now be included in a different scope. This also enables the possibility to pin a dependency. Dependencies which are likely to be used by other addons also shouldn’t be embedded - so they can be shared.

1 Like