google/dagger

Update of different dependency: Error "package javax.annotation.processing is not visible"

Closed this issue ยท 4 comments

In our project cryptomator/cryptofs, we use Dagger and also Google Guava.

When we update Google Guava from 33.0.0-jre to 33.1.0-jre, compilation fails with the error "package javax.annotation.processing is not visible". Looking into the error, only Dagger generated classes are affected, because by this external update, suddenly Dagger adds to every generated class the following annotation:

@Generated(
    value = "dagger.internal.codegen.ComponentProcessor",
    comments = "https://dagger.dev"
)

Prior to the dependency update, only the @DaggerGenerated annotation was present. I found #1339, but the project has already language level 17 as release target.

The fix inside an affected project is simple(add java.compiler to the module-info.java), but I'm wondering, how the change of an external dependency leads to a different generated source of dagger.

Dagger tries to find if the Generated annotation is on the class path and then outputs that if it is there, so there is probably some change there between the upgrading the versions that made it visible to the us?

https://github.com/google/dagger/blob/master/java/dagger/internal/codegen/base/SourceFileGenerator.java#L81 which uses https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspProcessingEnv.kt;l=173;drc=067ed409b9bc2dcc59b93c8e9ab8d092beeff3a5 (That's the KSP version. There's something similar for javac, but it is easier to see in the KSP version).

The fix is easy (add java.compiler to the module-info.java)

I'm not really that familiar with how the module-info.java stuff works, but is that a fix needed in Dagger?

Dagger tries to find if the Generated annotation is on the class path and then outputs that if it is there

Does that mean the generated annotation was not present on the classpath before and now it is? I searched the web a little more and it might be related to the fact, that dagger uses https://github.com/google/auto, which uses guava in turn. By updateing to the latest guava, there might have a been difference classpath order. Also found https://stackoverflow.com/a/53187201, which explains a little the annotation search and #1449 which might be related.

I'm not really that familiar with how the module-info.java stuff works, but is that a fix needed in Dagger?

My bad, this is not a fix in Dagger, this fix applies to an affected project. ๐Ÿ˜… I updated the my opening comment.

Does that mean the generated annotation was not present on the classpath before and now it is?

Yup I think so.

My bad, this is not a fix in Dagger, this fix applies to an affected project. ๐Ÿ˜… I updated the my opening comment.

Ah cool, thanks! Let me know if there's anything needed then in Dagger, otherwise I think this issue could probably be closed?

infeo commented

otherwise I think this issue could probably be closed?

I think so too. ๐Ÿ™ƒ