javaosgirequirements

Adding version requirements in OSGI capability


Does OSGI capabilities support versioning and how does it work? Say I have a module with the following declared:

Bundle-SymbolicName: my-module
Implementation-Version: 1.8.1-qualifier
Provide-Capability: org.foo.dependency;nameId="my-module",version="1.8.1-qualifier"

Would I then be able to add this require to get the module above?

Require-Capability: org.foo.dependency;filter:="&(nameId=my-module)(version>=1.8)"

Is there also a way to leverage Implementation-Version on the manifest if it's already specified in the provider module? I see references to osgi.wiring.bundle here. Would I be able to do this instead on the require:

Require-Capability: org.foo.dependency;filter:="(nameId=my.module)",osgi.wiring.bundle;filter:="(bundle-version>=1.8)"

Appreciate any pointers on the subject matter.


Solution

  • 1.8.1-qualifier is not a valid OSGi version. 1.8.1.qualifier is a valid OSGi version.

    &(nameId=my-module)(version>=1.8) is not a valid OSGi filter expression. You need to surround with parenthesis. (&(nameId=my-module)(version>=1.8))

    You cannot use Implementation-Version, but you can use Bundle-Version.

    Bundle-SymbolicName: my-module
    Bundle-Version: 1.8.1.qualifier
    
    Require-Capability: osgi.wiring.bundle;filter:="(&(osgi.wiring.bundle=my-module)(bundle-version>=1.8))"
    

    See https://docs.osgi.org/specification/osgi.core/8.0.0/framework.namespaces.html#framework.namespaces.osgi.wiring.bundle.