为什么不同组织的 javax.annotation 是不同的

why javax.annotation of different organization are different

我在 java 项目中使用 guava 和 jetty,但我发现了一个奇怪的问题。 在番石榴中,它取决于 javax.annotation 有这么多 class 而在码头中 javax.annotation 比番石榴少。它们有什么区别。

此外,jetty中的javax.annotation是有签名的,而guava中是没有签名的。当 jvm 从 guava.jar 和 jetty.jar 中的包 javax.annotation 加载 class 时,它会抛出 SecurityException,因为一个包已签名而其他包未签名。

那么,javax.annotation 包在 guava.jar 和 jetty.jar 之间的真正区别是什么。

guava中的包: no sign and has lot of class

码头包裹: signed and has little class

javax.annotations 包中有不同的库提供类型。 Guava 使用的是来自(现已废弃)JSR-305 proposal. In Maven this is com.google.code.findbugs:jsr305:1.3.9.

的一个 JAR

另一个 JAR 似乎是 org.eclipse.jetty.orbit:javax.annotation:1.1.0.v201108011116。目前尚不清楚该 JAR 从何而来,它似乎是在 2011 年上传的,此后就再也没有更新过。

这两个 JAR 之间的冲突似乎是 a well-known one

这个 JAR 上的 "dependency" 似乎是在 Guava release 13 中添加的,但该版本的发行说明说:

Made findbugs a provided dependency to avert dep conflicts when using findbugs 2.0. The side-effect of this change is that projects which relied upon Guava to grant access to the JSR-305 annotations "for free" will break unless they provide their own direct dependency on that jar (or an equivalent). Projects should always have been directly depending on JSR-305 (per maven best-practice), but this change makes that should into a must.

因此,据我了解,Guava 实际上对 com.google.code.findbugs:jsr305:1.3.9 JAR 没有任何依赖性。因此,您应该可以自由地排除该依赖项并提供您自己使用的 javax.annotations JAR。或者,如果您更喜欢 com.google.code.findbugs:jsr305 JAR,则应该从构建中排除 org.eclipse.jetty.orbit:javax.annotation 依赖项。你可以参考Maven documentation如何排除不需要的依赖。