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 121 forks source link

After adding dependency flagged as an undeclared used transitive, advice says to remove same dependency because it is unused #1029

Open joshfriend opened 1 year ago

joshfriend commented 1 year ago

Build scan link

Plugin version 1.25.0

Gradle version 8.3

JDK version 17

(Optional) Kotlin and Kotlin Gradle Plugin (KGP) version Kotlin 1.9.10

(Optional) Android Gradle Plugin (AGP) version AGP 8.1.1

(Optional) reason output for bugs relating to incorrect advice

$ ./gradlew -p common/bill-pay/payment-methods/impl reason --id deps.uisys.utils

> Task :common:bill-pay:payment-methods:impl:reason

----------------------------------------
You asked about the dependency 'com.squareup.ui.utils:uisys-android-utils:9.6.0 (deps.uisys.utils)'.
There is no advice regarding this dependency.
----------------------------------------

Shortest path from :common:bill-pay:payment-methods:impl to com.squareup.ui.utils:uisys-android-utils:9.6.0 (deps.uisys.utils) for debugCompileClasspath:
:common:bill-pay:payment-methods:impl
\--- register.common.container-inversion:public
      \--- register.uisys.components-mosaic:public
            \--- com.squareup.ui.utils:uisys-android-utils:9.6.0

Shortest path from :common:bill-pay:payment-methods:impl to com.squareup.ui.utils:uisys-android-utils:9.6.0 (deps.uisys.utils) for debugRuntimeClasspath:
:common:bill-pay:payment-methods:impl
\--- com.squareup.ui.market:uisys-android-market-components:9.6.0
      \--- com.squareup.ui.utils:uisys-android-utils:9.6.0

Source: debug, main
-------------------
(no usages)

Describe the bug DAGP in CI flags a dependency as unused when running buildHealth on the set of common projects:

> Advice for :common:bill-pay:payment-methods:impl
  These transitive dependencies should be declared directly:
    implementation deps.uisys.utils

Running projectHealth locally on this same commit returns no issue.

When I add the requested dependency requested by the CI failure, buildHealth returns:

> Advice for :common:bill-pay:payment-methods:impl
  Unused dependencies which should be removed:
    implementation deps.uisys.utils

I ran projectHealth locally and it reports the same conclusion.

To Reproduce Steps to reproduce the behavior:

  1. Checkout commit e917cfb80c61bde10f93713a095b24e09f5fb8c4 of the relevant repo
  2. run ./gradlew -p common/bill-pay/payment-methods/impl projectHealth. It does not report the same result as buildHealth run in CI (see above)

Expected behavior One and only one of the above suggestions should is correct and DAGP should provide that one, not both 😄

autonomousapps commented 1 year ago

I checked out the indicated commit and ran projectHealth locally and get that same error that CI apparently reported:

$ git checkout e917cfb80c61bde10f93713a095b24e09f5fb8c4
$ ./gradlew :common:bill-pay:payment-methods:impl:projectHealth

> Task :common:bill-pay:payment-methods:impl:projectHealth FAILED

* What went wrong:
Execution failed for task ':common:bill-pay:payment-methods:impl:projectHealth'.
> These transitive dependencies should be declared directly:
    implementation deps.uisys.utils

and when I run reason, I get this output

> Task :common:bill-pay:payment-methods:impl:reason

----------------------------------------
You asked about the dependency 'com.squareup.ui.utils:uisys-android-utils:9.6.0 (deps.uisys.utils)'.
You have been advised to add this dependency to 'implementation'.
----------------------------------------

Shortest path from :common:bill-pay:payment-methods:impl to com.squareup.ui.utils:uisys-android-utils:9.6.0 (deps.uisys.utils) for debugCompileClasspath:E
:common:bill-pay:payment-methods:impl
\--- register.common.container-inversion:public
      \--- register.uisys.components-mosaic:public
            \--- com.squareup.ui.utils:uisys-android-utils:9.6.0

Shortest path from :common:bill-pay:payment-methods:impl to com.squareup.ui.utils:uisys-android-utils:9.6.0 (deps.uisys.utils) for debugRuntimeClasspath:
:common:bill-pay:payment-methods:impl
\--- com.squareup.ui.market:uisys-android-market-components:9.6.0
      \--- com.squareup.ui.utils:uisys-android-utils:9.6.0

Source: debug, main
-------------------
* Uses 1 resource: AttrRef(type=attr, id=sqBoldWeight) (implies implementation).
autonomousapps commented 1 year ago

Currently cannot reproduce.