autonomousapps / autonomousapps/dependency-analysis-gradle-plugin

Bundles prevent unused dependencies from working

Open
#1,626 1 comment 0 reactions 0 assignees View on GitHub
bug toolchain:android
Dominant language
Kotlin
Stars
2.2k
Forks
158
Avg merge
16h 25m
Merged PRs (30d)
46

Description

**Plugin version**
3.5.1

**Gradle version**
9.2.1

**JDK version**
21

**(Optional) Kotlin and Kotlin Gradle Plugin (KGP) version**
2.2.1

**(Optional) Android Gradle Plugin (AGP) version**
8.13.1

**(Optional) `reason` output for bugs relating to incorrect advice**

```
------------------------------------------------------------
You asked about the dependency 'androidx.datastore:datastore-preferences-android:1.2.0'.
There is no advice regarding this dependency.
------------------------------------------------------------

Shortest path from :app to androidx.datastore:datastore-preferences-android:1.2.0 for debugCompileClasspath:
:app
\--- androidx.datastore:datastore-preferences:1.2.0
\--- androidx.datastore:datastore-preferences-android:1.2.0

Shortest path from :app to androidx.datastore:datastore-preferences-android:1.2.0 for debugRuntimeClasspath:
:app
\--- androidx.datastore:datastore-preferences:1.2.0
\--- androidx.datastore:datastore-preferences-android:1.2.0

Shortest path from :app to androidx.datastore:datastore-preferences-android:1.2.0 for debugUnitTestCompileClasspath:
:app
\--- androidx.datastore:datastore-preferences:1.2.0
\--- androidx.datastore:datastore-preferences-android:1.2.0

Shortest path from :app to androidx.datastore:datastore-preferences-android:1.2.0 for debugUnitTestRuntimeClasspath:
:app
\--- androidx.datastore:datastore-preferences:1.2.0
\--- androidx.datastore:datastore-preferences-android:1.2.0

Shortest path from :app to androidx.datastore:datastore-preferences-android:1.2.0 for debugAndroidTestCompileClasspath:
:app
\--- androidx.datastore:datastore-preferences:1.2.0
\--- androidx.datastore:datastore-preferences-android:1.2.0

There is no path from :app to androidx.datastore:datastore-preferences-android:1.2.0 for debugAndroidTestRuntimeClasspath

Shortest path from :app to androidx.datastore:datastore-preferences-android:1.2.0 for releaseCompileClasspath:
:app
\--- androidx.datastore:datastore-preferences:1.2.0
\--- androidx.datastore:datastore-preferences-android:1.2.0

Shortest path from :app to androidx.datastore:datastore-preferences-android:1.2.0 for releaseRuntimeClasspath:
:app
\--- androidx.datastore:datastore-preferences:1.2.0
\--- androidx.datastore:datastore-preferences-android:1.2.0

Shortest path from :app to androidx.datastore:datastore-preferences-android:1.2.0 for releaseUnitTestCompileClasspath:
:app
\--- androidx.datastore:datastore-preferences:1.2.0
\--- androidx.datastore:datastore-preferences-android:1.2.0

Shortest path from :app to androidx.datastore:datastore-preferences-android:1.2.0 for releaseUnitTestRuntimeClasspath:
:app
\--- androidx.datastore:datastore-preferences:1.2.0
\--- androidx.datastore:datastore-preferences-android:1.2.0

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

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

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

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

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

**Describe the bug**

It seems when a dependency is part of a bundle (which would suppress "transitive dependencies should be declared directly"), it also suppresses the unused dependencies check.

**To Reproduce**
Steps to reproduce the behavior:

1. Create a new blank Android project
2. Add the dependency analysis plugin
3. Add the following dependency to the `:app`: `implementation("androidx.datastore:datastore-preferences:1.2.0")`
4. Run the `buildHealth`
5. Note that it correctly suggests that the `datastore-preferences` is unused and should be removed
6. Add the following bundle config to the root gradle:

```kotlin
dependencyAnalysis {
structure {
bundle("datastore") {
includeGroup("androidx.datastore")
}
}
}
```

7. Run the `buildHealth` again
8. note that now it does not report anymore that the `data-preferences` is unused

For your convenience, here is the pre-prepared demo project: [DependencyBugDemo.zip](https://github.com/user-attachments/files/24251876/DependencyBugDemo.zip)

**Expected behavior**

Plugin should report unused dependencies regardless of the bundles

Contributor guide

Open the contributing guide

Research direction

Start with the attached DependencyBugDemo.zip and reproduce the behavior by running buildHealth before and after adding the dependencyAnalysis structure bundle. Trace how bundle configuration affects unused-dependency advice; done means the androidx.datastore:datastore-preferences dependency is still reported as unused when the bundle is present.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.