autonomousapps / autonomousapps/dependency-analysis-gradle-plugin
Unused dependency false positive if Hilt Gradle Plugin is applied
- Dominant language
- Kotlin
- Stars
- 2.2k
- Forks
- 158
- Avg merge
- 16h 25m
- Merged PRs (30d)
- 46
Description
**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](https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin/files/9652293/HiltDependencyExample.zip)
Contributor guide
Research direction
Start with the attached HiltDependencyExample.zip and run ./gradlew app:projectHealth using the reported plugin, Gradle, and AGP versions. Compare the reason output for :impl with the expected dependency usage, then run testReleaseUnitTest; done means projectHealth no longer advises removing :impl and the test still succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100