2

I have an issue where I am building a war using maven war plugin and overlaying it using bnd plugin as described in Adding OSGi metadata to existing projects without changing the packaging type. This project defines the following dependency:

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.12</version>
    </dependency>

When I run the build, it generates the following entry in MANIFEST.MF

Import-Package: .., javax.ws.rs.core,  ..

As soon as I change the version to 1.13 or higher the Import-Package entry becomes:

Import-Package: .., javax.ws.rs;version="[1.1,2)", ..

Which becomes a real problem for me because my target has javax.ws.rs.javax.ws.rs-api_2.0.0.m16 in it. Which will resolve the import for the no version required case, but stops doing so when the range restriction is there.

So, my general question is: How does bnd decide that version range? Something changed between the two minor releases to make it go from no version restriction to that particular range so I think understanding how bnd makes that decision will help lead me to discovering what this particular issue is.

mate64
  • 9,876
  • 17
  • 64
  • 96
harschware
  • 13,006
  • 17
  • 55
  • 87

1 Answers1

9

Bnd uses OSGi Semantic Versioning -- please read the whitepaper (PDF link).

First, bnd works out which version of the package was used at build time. The JSR311 API Jar that you had on your build path must have contained a versioned Export-Package statement, which is good, and that version must have been 1.1. Therefore, the lowest version of that package that your bundle can use is 1.1.

Semantic Versioning says that the Major (i.e. first) segment is incremented to indicate a breaking change for all users. Therefore your bundle will NOT be compatible with version 2.* of the javax.ws.rs package. So bnd generates a range up to but not including 2... i.e, [1.1,2).

I don't see why this would cause you a problem. You stated that you want to deploy a bundle called javax.ws.rs.javax.ws.rs-api_2.0.0.m16 into your target, but that just looks like a filename. Have you checked whether the package javax.ws.rs inside the bundle is version 2? If it still version 1.* then you can use it... if it is version 2.* then it means the package contains breaking changes, so you shouldn't use it. Finally if the version of the package is 2.* but it isn't really a breaking change, then whoever created that bundle has screwed up and they need to go back and read the PDF I linked to.

Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77