autonomousapps / dependency-analysis-gradle-plugin

Gradle plugin for JVM projects written in Java, Kotlin, Groovy, or Scala; and Android projects written in Java or Kotlin. Provides advice for managing dependencies and other applied plugins
Apache License 2.0
1.82k stars 120 forks source link

False positive for removal of annotation library #1290

Closed baron1405 closed 4 weeks ago

baron1405 commented 1 month ago

Plugin version 2.2.0

Gradle version 8.10.2

JDK version 17

(Optional) reason output for bugs relating to incorrect advice Report says, incorrectly:

Advice for root project
Unused dependencies which should be removed:
  implementation(libs.cthingAnnots)

The libs.cthingAnnots is an alias for org.cthing:cthing-annotations:1.0.0.

The reason output says, correctly:

> Task :reason

----------------------------------------
You asked about the dependency 'org.cthing:cthing-annotations:1.0.0 (libs.cthingAnnots)'.
You have been advised to remove this dependency from 'implementation'.
----------------------------------------

Shortest path from root project to org.cthing:cthing-annotations:1.0.0 (libs.cthingAnnots) for compileClasspath:
:
\--- org.cthing:cthing-annotations:1.0.0

Shortest path from root project to org.cthing:cthing-annotations:1.0.0 (libs.cthingAnnots) for runtimeClasspath:
:
\--- org.cthing:cthing-annotations:1.0.0

Shortest path from root project to org.cthing:cthing-annotations:1.0.0 (libs.cthingAnnots) for testCompileClasspath:
:
\--- org.cthing:cthing-annotations:1.0.0

Shortest path from root project to org.cthing:cthing-annotations:1.0.0 (libs.cthingAnnots) for testRuntimeClasspath:
:
\--- org.cthing:cthing-annotations:1.0.0

Source: main
------------
* Uses (in an annotation) 1 class: org.cthing.annotations.PackageNonnullByDefault (implies implementation (sometimes)).

Source: test
------------
(no usages)

Describe the bug The library is used in the package-info.java files.

To Reproduce Steps to reproduce the behavior:

  1. Clone the project https://github.com/cthing/gradle-build-constants
  2. Run ./gradlew clean build
  3. Notice there are no dependency errors reported
  4. Open the `gradle/libs.versions.toml file
  5. Change the version of the com.autonomousapps.dependency-analysis from 1.32.0 to 2.2.0
  6. Run ./gradlew clean build
  7. Notice that the build fails due to a supposedly unused dependency on org.cthing:cthing-annotations:1.0.0

Expected behavior The build should succeed because the dependency is used. Note that the build succeeds using plugin version 1.32.0, but fails using plugin version 2.2.0.

autonomousapps commented 4 weeks ago

Thanks for the issue. When you say

The library is used in the package-info.java files.

Could you please elaborate?

autonomousapps commented 4 weeks ago

I'll have a fix in the next release, sometime today 👍

baron1405 commented 4 weeks ago

Thanks @autonomousapps for looking into this. It appears you have reproduced the problem and have a fix. In any case, to answer your question, the library in question provides annotations and the only place in my code where I use those annotations is in the package-info.java file. For example, think of using the jsr305 ParametersAreNonnullByDefault annotation in the package-info.java file so that it effects all code within that package.