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.7k stars 116 forks source link

Unused dependency false positive if Hilt Gradle Plugin is applied #791

Open BenTilbrook opened 1 year ago

BenTilbrook commented 1 year ago

Description When the Hilt Gradle Plugin is applied (Hilt can be used without the Gradle plugin, but this issue pertains to when the plugin is in use), Dependency Analysis Gradle Plugin falsely considers a project dependency unused, when in fact it is used.

In the attached sample project below, run the command ./gradlew app:projectHealth. It should succeed due to no unused dependencies, but it fails, falsely flagging :impl as unused.

If Hilt Gradle Plugin is applied is not applied, the Dependency Analysis Gradle Plugin gives correct advice.

If you run ./gradlew testReleaseUnitTest after applying the plugin's false advice, the build will fail, demonstrating that the dependency is required.

Build scan link https://gradle.com/s/k7vtaivpaxksc

Plugin version 1.13.1

Gradle version 7.5.1

Android Gradle Plugin (AGP) version 7.3.0

reason output for bugs relating to incorrect advice


> Task :app:reason

----------------------------------------
You asked about the dependency ':impl'.
You have been advised to remove this dependency from 'implementation'.
----------------------------------------

Shortest path from :app to :impl for debugCompileClasspath:
:app
\--- :impl

Shortest path from :app to :impl for debugRuntimeClasspath:
:app
\--- :impl

Shortest path from :app to :impl for debugUnitTestCompileClasspath:
:app
\--- :impl

Shortest path from :app to :impl for debugUnitTestRuntimeClasspath:
:app
\--- :impl

Shortest path from :app to :impl for releaseCompileClasspath:
:app
\--- :impl

Shortest path from :app to :impl for releaseRuntimeClasspath:
:app
\--- :impl

Shortest path from :app to :impl for releaseUnitTestCompileClasspath:
:app
\--- :impl

Shortest path from :app to :impl for releaseUnitTestRuntimeClasspath:
:app
\--- :impl

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

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

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

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

Describe the bug

To Reproduce Steps to reproduce the behavior:

  1. Run ./gradlew app:projectHealth in attached sample project

Expected behavior Plugin does NOT advise to remove dependency :impl

Actual behavior Plugin advises to remove :impl.

Sample project See attached.

HiltDependencyExample.zip

autonomousapps commented 1 year ago

Thanks for the report and the reproducer!

autonomousapps commented 10 months ago

Do you know if this issue still exists in the latest version (1.24.0 at time of writing)?

simonlebras commented 9 months ago

I'm still having the issue with 1.24 on my project => https://github.com/simonlebras/rickandmorty/blob/main/app/build.gradle.kts#L120 (if I remove this block, the check will fail)

autonomousapps commented 6 months ago

Unfortunately I don't have time to work on this. I have added the sponsorable label to indicate that I could shift my priorities if someone wants to sponsor the work. PRs are also welcome.

kelmer44 commented 1 month ago

Also ran into this problem, dependency-analysis would somehow false positive with coil even after disabling hilt 🤷