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

False positive unused dependency on debugImplementation for Compose ui-tooling

Open eygraber opened this issue 6 months ago • 6 comments
trafficstars

Plugin version 2.16.0

Gradle version 8.13

JDK version 23

Kotlin and Kotlin Gradle Plugin (KGP) version 2.1.20

Android Gradle Plugin (AGP) version 8.9.2

Describe the bug All of my UI modules have a debugImplementation on androidx.compose.ui:ui-tooling which was fine until one of the versions of DAGP released in the past few weeks, when I started noticing that after some time I got false positives for each UI module saying:

Unused dependencies which should be removed:
    debugImplementation(libs.compose.ui.tooling)

Running buildHealth with --no-configuration-cache --no-build-cache --rerun-tasks fixes the problem temporarily. I've added that artifact to my excludes for now.

I'm trying to repro in a shareable project, and will update if I can.

eygraber avatar Apr 24 '25 04:04 eygraber

Thanks for the issue. I'll need more information to investigate the root cause. A reproducer and the version of the plugin where the issue was introduced. It's also interesting that this might relate to the build cache (if --rerun-tasks works around it).

If you can save the output from the build/reports/dependency-analysis directory in the suspect module, for both the "good" and "bad" cases, then I could also diff those and that might illuminate the issue.

autonomousapps avatar Apr 28 '25 06:04 autonomousapps

I'll grab the output from build/reports/dependency-analysis next time this happens. I would do a bisect to find the version it started in, but I'm still not fully sure what is triggering it to happen.

eygraber avatar Apr 28 '25 16:04 eygraber

When you have the two sets of build/ dirs, if you want to narrow it down yourself, use diff --brief --recursive good/ bad/ and it'll show the files that are different. Those will be json files, which you can format with your favorite json formatter and then diff individually. In two builds on the same commit, there should be no diff at all, so any diff is a bug. (You can also share these with me, perhaps via email if you don't want to drop on this public issue tracker.)

autonomousapps avatar Apr 28 '25 17:04 autonomousapps

Here are the zipped build directories from one of the modules that had the issue (the bad one was first, then I re-ran with --rerun-tasks to get the good one).

Still don't know exactly what triggers it, but this happened after updating the Compose BOM version.

good.zip

bad.zip

eygraber avatar May 20 '25 18:05 eygraber

After the good.zip in the comment above, I updated androidx.compose.material3:material3 and got the issue again.

bad_again.zip

Edit: This one had legitimate failures as well, but the ui-tooling showed up with them.

eygraber avatar May 20 '25 18:05 eygraber

Thanks!

autonomousapps avatar May 20 '25 20:05 autonomousapps

I got a similar problem but in reverse, but possibly related:

  • We get a false positive on androidx.compose.ui:ui-test-manifest in CI which is added as a debugImplementation
  • Originally it triggered the onRuntimeOnly check
  • With 1.8.3 and the compose 2025.06.01 BOM of that dep, in CI, which ran with --no-configuration-cache and --no-build-cache it changed to onUnusedDependencies.
  • Locally running the same change/branch as CI but with the config cache and build cach locally seemed to pass. Adding --no-configuration-cache and --no-build-cach caused it to fail as "expected" (although it's a false positive)
  • After adding an excludes, running with -no-configuration-cache and --no-build-cache, and passing, and then removing from excludes and running again it continues to pass instead of failing.
  • Eventually no matter what I do, I can't get projectHealth to fail.

AlexanderGH avatar Jun 20 '25 03:06 AlexanderGH