Fix shaded Guava annotation refs breaking -Xlint:classfile consumers - #4437
Fix shaded Guava annotation refs breaking -Xlint:classfile consumers#4437kalayciburak wants to merge 1 commit into
Conversation
Relocate and ship Guava annotation packages (common.annotations, errorprone, j2objc, checker-qual, jsr305) with the minimized Guava shade so RuntimeInvisibleAnnotations on ImmutableList and friends no longer point at types absent from the published jar. Consumers compiling with -Xlint:classfile -Werror (e.g. Spring for GraphQL) failed on those dangling descriptors. Add a packaging check and Spock guard for the published jar. Fixes graphql-java#4436 Signed-off-by: Burak KALAYCI <kalayciburak1996@gmail.com>
|
@kalayciburak did you check how much this adds to the resulting JAR? Is this only adding the relevant classes or the entire contents of the JAR because those are excluded from the minimize task? |
|
minimize exclude pulls the whole annotation jars, not just the types the shaded Guava classfiles point at. on 26.0 (3.7mb) thats about +270kb, almost all checker-qual (~224kb). jsr305 + error_prone + j2objc together are ~45kb. the classfiles only actually reference 26 annotation types though, ~7kb compressed if we keep just those. i can slim it to the referenced types if youd rather not ship the rest. |
|
@kalayciburak I'm not part of the graphql-java team so I'll defer to them. I was wondering about the implications of this change. I tried myself to implement an alternative fix, but this involves listing all the relevant annotations manually - so pretty hard to maintain and test. While this problem is still worth looking into, I have also found new information. |
|
looks like #4445 already landed the annotation cleanup on master, so this include-the-jars approach is obsolete. closing |
|
Sorry for not commenting earlier @kalayciburak : we appreciate all contributions and your PR helped us to decide how to solve it. Thanks |
Summary
Fixes #4436.
The published jar shades a minimized subset of Guava under
graphql.com.google.common, but classfiles such asImmutableListkeepRuntimeInvisibleAnnotationsthat reference annotation types that were never included:com.google.common.annotations.GwtCompatible(and related)com.google.errorprone.annotations.DoNotCall/InlineMe/ …com.google.j2objc.annotations.*org.checkerframework.*javax.annotation.*Consumers that compile with
-Xlint:classfile -Werror(reported from Spring for GraphQL against 26.0) fail withCannot find annotation method … class file for … not found.Change
shadowJar(withminimizeexcludes so they are retained).Import-Packagefrom re-exporting the shaded packages.verifyShadedJarAnnotationRefs(wired intocheck/ afterbuildNewJar) andShadedJarAnnotationRefsTestso a regression fails the packaging pipeline.Test plan
Executed locally:
javac --release 17 -Xlint:classfile -Werror -cp <published-jar> …againstgraphql.com.google.common.collect.ImmutableListfailed with missingGwtCompatible/DoNotCall/InlineMeclassfilesexit 0)./gradlew shadowJar verifyShadedJarAnnotationRefsSUCCESS./gradlew test --tests graphql.ShadedJarAnnotationRefsTest --tests graphql.GuavaLimitCheck --tests 'graphql.collect.*' --tests 'graphql.relay.*'— 38 tests GREEN