Hi Attila,
It seems like the problem is with this line in bnd:
Class<T> c = (Class<T>) getClass().getClassLoader().loadClass(cname);
https://github.com/bndtools/bnd/blob/master/biz.aQute.bndlib/src/aQute/bnd/osgi/Annotation.java#L66
That is, it's trying to load the annotation from the ClassLoader that
bnd itself is running under. I'm not sure why it does that. I don't
follow Peter's explanation that this avoids inadvertently running
unintended code: it seems possible to create a ClassLoader (or use one
in such a way) that it never initialises any classes. If this were
combined with reflection, bnd could use the annotations on the bundle
classpath, rather than on it's own classpath.
However, there seems to be a workaround that doesn't involve using
-fail ok: you can add the javax.annotation as a plugin dependency so
that it's present the same ClassLoader that bnd is loaded under. Ugly,
but it seems to work.
Here's an example:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<_dsannotations>*</_dsannotations>
</instructions>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</plugin>
Martin