Skip to content

Shaded google dependency points to dangling annotation references #4436

Description

@bclozel

Hi team,

I have been running Spring for GraphQL tests against GraphQL Java 26.0 for a while now.
But as I'm preparing for the next minor version, I am trying to compile the project against 26.0 and getting compiler warnings like this.

:spring-graphql:compileJava FAILED	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'serializable()' in type 'GwtCompatible': class file for com.google.common.annotations.GwtCompatible not found	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'emulated()' in type 'GwtCompatible'	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'value()' in type 'DoNotCall': class file for com.google.errorprone.annotations.DoNotCall not found	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'value()' in type 'DoNotCall'	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'value()' in type 'DoNotCall'	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'value()' in type 'DoNotCall'	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'value()' in type 'DoNotCall'	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'value()' in type 'DoNotCall'	
/Users/bclozel/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/26.0/d1a1d3005ca6f4a87b4a985a1907b22bf5b63700/graphql-java-26.0.jar(/graphql/com/google/common/collect/ImmutableList.class): warning: [classfile] Cannot find annotation method 'replacement()' in type 'InlineMe': class file for com.google.errorprone.annotations.InlineMe not found	
error: warnings found and -Werror specified

This is breaking my build since it's compiling with javac -Xlint:classfile -Werror

It looks like 26.0 shades relocated Guava classes (like graphql.com.google.common.collect.ImmutableList) whose bytecode still carries RuntimeInvisibleAnnotations referencing the original relocated annotation
types:

  • com.google.common.annotations.GwtCompatible
  • com.google.errorprone.annotations.DoNotCall
  • com.google.errorprone.annotations.InlineMe

Those classes are not present in the jar and this causes the compiler issues.

You can reproduce this with a minimal build like and run compileJava:

dependencies {
    implementation 'com.graphql-java:graphql-java:26.0'
}

tasks.withType(JavaCompile).configureEach {
    options.compilerArgs += ['-Xlint:classfile', '-Werror']
}

I can't reproduce this with 25.0, but I'm not sure when/how this was introduced.
I guess the shadowJar task configuration must be updated to avoid such problems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions