autonomousapps / autonomousapps/dependency-analysis-gradle-plugin

Kotlin removes unreachable bytecode causing DAGP to think a dependency is unused

Open
#1,429 5 comments 0 reactions 0 assignees View on GitHub
bug help wanted sponsorable toolchain:kotlin
Dominant language
Kotlin
Stars
2.2k
Forks
158
Avg merge
16h 25m
Merged PRs (30d)
46

Description

**Plugin version**
2.17.0

**Gradle version**
8.14

**JDK version**
17

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

**Describe the bug**
Kotlin optimizes out unreachable bytecode like `if (false)` so if a usage of a dependency is inside of that block, DAGP considers it unused and will remove it. Removing it causes a compilation failure.

**To Reproduce**
Steps to reproduce the behavior:
1. In the attached project, `:app:fixDependencies` removes the dependency on `:utils`
2. Running `:app:assemble` will have a compilation error because the dependency was removed

**Expected behavior**
The `:utils` dependency should not be removed by `fixDependencies` and should be reported in build health as being used.

[dagp-if-false-repro.zip](https://github.com/user-attachments/files/19984820/dagp-if-false-repro.zip)

Contributor guide

Open the contributing guide

Research direction

Unpack dagp-if-false-repro.zip and run :app:fixDependencies, then :app:assemble to reproduce the dependency removal and compilation failure. Trace how the plugin analyzes the :utils usage in the :app project, especially code optimized from if (false). Done means :utils remains reported as used and is not removed by fixDependencies.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.