google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.4k stars 2.01k forks source link

hiltJavaCompile task loads deprecated annotation processors #4116

Open G00fY2 opened 10 months ago

G00fY2 commented 10 months ago

We migrated our project to 100% KSP (Hilt 1.1.0-rc01, Room 2.6.0, Moshi 1.15.0) and removed all usages of kapt. Still we see a deprecation warning which should only be shown if the deprecated Moshi Code Gen Annotation Processor is being loaded into kapt/apt. See this build log from a minimal reproducible example project: https://github.com/G00fY2/HiltMoshiKaptWarning/actions/runs/6683702355/job/18160177116#step:5:44

I started a discussion in the Moshi project to make sure that this is not something wrong on Moshi's side: https://github.com/square/moshi/discussions/1752

@ZacSweers pointed out in that discussion that hiltJavaCompile task is capturing all KSP and kapt dependencies and passing them on to the JavaCompile task it creates. This causes the actually unused Code Gen Processor to print a deprecation warning.

Not sure what's the reason behind this. But would be nice if dagger/hilt would not load these classes and potentially mislead users.

danysantiago commented 10 months ago

That's right, the HiltGradlePlugin will configure the annotation processor classpath of the hiltJavaCompile to be a mirror of the kapt and ksp configurations. This is done for convenience such that if you have SPI Plugins or any other processor that does further code generation after Dagger, that it is done in the JavaCompile task where Dagger runs after Hilt codegen. Since moshi-kotlin-codegen ships both its KSP and JavaAP processors in the same artifacts, the JavaAP processor ends up being loaded for the JavaCompile task even though it will likely not run as no new annotations triggered by it will be present in the sources being compiled.

There are some options we can do here, but they all have some sort of pros-cons:

mkubiczek commented 7 months ago

How can I suppress this specific error when -Werror compiler flag is used?

bcorso commented 7 months ago

How can I suppress this specific error when -Werror compiler flag is used?

I think you'll have better luck asking on StackOverflow.