@org.osgi.annotation.bundle.Export with -includeresource

Not sure if this is a Bug of a Feature:

The Moment I define a -includeresource instruction, we don’t look for @Export anymore and every package becomes excluded. I do understand that we ignore them, as soon as I manually define Import or Export packages, but an the -includeresource instruction should not deactivate this feature.

Do I misunderstand something here?

There should be no relationship. But it you specify -includeresource, then Bnd will not automatically -includepackage all of the packages in the output folder, so there may be no package in the bundle which may have Export annotations.

Now I’m more confused then before. Should there be a relationship between -includeresource and the interpretation of Export Annotations or not? If I read your statement correctly, then -includeresource will deactivate the interpretation of Bundle Annotations.

If so, I think this is highly misleading. In my understanding -includeresource should be used to add things like e.g. property files or other static content. I don’t see a reason, why this would block me from using the Bundle annotations.

Do we have an instruction to tell bnd to look for annotations anyway?

As I said, there is no relationship. Bnd will process all packages (which are not -privatepackage or Private-Package) in the bundle for Export annotations.

My point is about what packages are actually in the bundle. By default, Bnd will include all the packages in the project which are compiled into the bin folder. But if your Bnd instructions use -includeresource, or -includepackage, or Export-Package, then Bnd assumes you are in full control of what goes in the bundle and Bnd will not automatically include all the packages from the bin folder. See https://github.com/bndtools/bnd/blob/a211ec952529d2cf70ef7155f379064cd5c0457f/biz.aQute.bndlib/src/aQute/bnd/build/ProjectBuilder.java#L768-L800

It might be already to late to change this, but making -includeresource part of this assumption is a bit much for my taste.

Can we change this or alternatively introduce an instruction to do process them anyway?

This behavior has been in place since Bnd 3.2.0. So I think it is a bit late to reverse course now. The principle is either you fully control the bundle content, or Bnd defaults to the content of the output folder. Some blending of the two can be confusing.

I agree with Jürgen that we messed up with this. For my customers I always set the following in the build.bnd nowadays to prevent this problem:

-includepackage.x             *;from:=classes  # classes= the src output directory
-includeresource.x            -src/main/resources/

This creates the expected behavior but does not throw its hands in the air when there is even the tiniest hint the user like to say something about the content.

I recall I wrote something about this a few months ago. One note, I created a recent fix when there are no packages in the source directory, this created an incorrect error.

1 Like

Works like charm! Thanks heaps.