dependency-analysis-gradle-plugin icon indicating copy to clipboard operation
dependency-analysis-gradle-plugin copied to clipboard

Ignoring unused annotation processors causes a new warning about unused kapt plugin

Open ofalvai opened this issue 3 years ago • 3 comments
trafficstars

Build scan link

Plugin version 1.2.1

Gradle version

7.4.2

(Optional) Android Gradle Plugin (AGP) version

reason output for bugs relating to incorrect advice

Describe the bug

I had a false positive warning about unused annotation processors, so I wanted to ignore them by:

onUnusedAnnotationProcessors {
    severity("fail")
    exclude("com.airbnb.android:epoxy-processor", "com.google.dagger:hilt-compiler") // False positives
}

After this change, I don't get the warnings anymore, but a new item popped up:

Unused plugins that can be removed:
  kotlin-kapt: this project has the kotlin-kapt (org.jetbrains.kotlin.kapt) plugin applied, but there are no used annotation processors.

To Reproduce Steps to reproduce the behavior:

  1. Have a warning about an unused annotation processor
  2. Add an exclusion for that kapt dependency
  3. Re-run analysis

Expected behavior Missing warning about the dependency, without new warnings appearing

Additional context

ofalvai avatar May 18 '22 15:05 ofalvai

Thanks for the report!

Do you happen to have a reproducer? I'm surprised that the unused plugin advice only appears once you exclude the warnings about unused annotation processors. The former is caused by this.

There is no strong relationship between the dependency advice (which includes unused annotation processors) and unused plugin advice; they're independent.

autonomousapps avatar May 21 '22 16:05 autonomousapps

I see, thank you for the context and explanation. Maybe it's a false alarm then, connecting the two seemed logical when I noticed it first.

By the way, I was working on this PR when encountered this "bug". Any tips how to debug this further?

ofalvai avatar May 26 '22 06:05 ofalvai

I noticed you have this

           onUsedTransitiveDependencies {
                // Transitively used dependencies that should be declared directly
                severity("ignore")
            }

That can lead to advice that seems like false positives but is actually accurate. If you remove a dependency, you may also be removing all of its transitive dependencies if it was the only one supplying them. And if you are using one of those transitives, then your project may no longer compile. Then, you might think "oh, that advice that such-and-such a dependency is unused was just a false positive, I should filter it out."

The other thing you can do to "debug" the advice is to use the reason task. For example:

./gradlew :library:jsonviewer:reason --id org.json:json

The output of that is often illuminating.

If you have any specific questions, feel free to ask here. It's hard to provide general advice other than what I just gave.

autonomousapps avatar May 27 '22 05:05 autonomousapps

Duplicate: https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin/issues/778

autonomousapps avatar Nov 14 '22 18:11 autonomousapps