Javac problems with classes using @ServiceProvider annotation

Just FYI, I tried to help FasterXML add some missing @ServiceProvider annotations to Jackson, but it did not end well.

Not sure what else can be done here :thinking:.


Similar misery now being reported here. Any idea how to fix this please? (Other that hand-writing the OSGi metadata, which I consider to be fragile and error-prone.)


I would just do the manifest headers … Its easy, will never cause these kind of problems. The annotations are nice for OSGi builds but they quickly annoy other people because they ‘don’t get them’.

Manifest headers are a bit more work on your side but they have much wider acceptance.

The advantage of using annotations is that the metadata will probably remain correct after someone else (who most likely won’t have a clue about OSGi) decides to refactor those packages.

I think the compiler issue revolves around the use of an Enum in the annotation, which I added to make the requirement “optional”.

We can replace the use of enums. I did this same thing for the OSGi annotations and it is was fully source compatible and Bnd doesn’t care if they are enums or Strings.

Thanks, although if Bnd 7.0.0 will require Java 17 then I’d likely need a 6.4.1 release in order to use it. (Although this sounds like a binary-incompatible change… :person_facepalming:)

No, because the annotations are CLASS retention (and processed by Bnd tooling), there is no runtime aspect for which there could be binary incompatibility.

Your build system cannot use Java 17?

I’m actually helping out the FasterXML guys here, but FWIW we are still targeting Java 11 too.

It is not about what version you target, but what JDK you build with. OSGi still targets Java 8 (--release 8) but builds with JDK 17.

We’re using Gradle toolchains, so the compiler will run on Java 11 even if Gradle itself may be running on Java 17.

Great, so then Bnd Gradle plugins will be running in the Gradle Java 17 VM.

Although that won’t be enough:

    implementation("biz.aQute.bnd:biz.aQute.bndlib:$bndVersion") {
        transitive = false

I am not sure what the problem is there. If running in a OSGi environment, then pom dependencies are meaningless.

We’re using some code from bndlib at various places, and I’m assuming it will also become Java 17. Which means it won’t run on a Java 11 JVM, of course.