You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Dead Code Detector Gradle Plugin (Android Edition)
3
2
4
-
**Dead Code Detector** is a Kotlin-based Gradle plugin that analyzes compiled classes, resources, and dependencies, generating a human-readable report of unused (dead) code, resources, and libraries in your project.
3
+
> ⚠️ Android support is in progress
4
+
5
+
**Dead Code Detector** is a Kotlin-based Gradle plugin that analyzes compiled classes, Android resources, and dependencies, generating a report of unused (dead) code and libraries in your project.
keepAnnotations.add("javax.inject.Inject") // Ignore elements with annotations
104
146
}
105
147
```
106
148
107
-
### Notes about configuration
149
+
**Notes:**
108
150
109
-
*If you want to detect unused public API, set `keepPublicApi = false`. Be careful: this may flag intentionally public functions used by other modules or reflective consumers.
110
-
* If you enable `includeResources`, the plugin will scan your resource directories (`resourceDir`, `testResourceDir`) for unused entries.
111
-
* If you want to detect unused dependencies, simply run the plugin — unused dependency detection is included in the report.
112
-
* If the plugin cannot find compiled classes, run `./gradlew classes` (or your module's compile tasks) before running the detector.
151
+
*Run after building the app (`./gradlew assembleDebug`) so compiled classes and resources exist.
152
+
* If `keepPublicApi = false`, public functions/classes may be flagged even if used by other modules.
153
+
154
+
---
113
155
114
156
## Tasks
115
157
116
-
*`deadCodeDetector` — main task that scans compiled classes, resources, and dependencies, producing the report
117
-
* Integration with `check` — if wired in the plugin, `./gradlew check` will run the detector (depending on configuration)
158
+
*`deadCodeDetectorDebug` — scans the debug variant
159
+
*`deadCodeDetectorRelease` — scans the release variant
160
+
* Integration with `check` can be added for CI pipelines
118
161
119
-
## Report format & example
162
+
---
120
163
121
-
The report is a plain text file grouped by dead classes, methods, fields, resources, and dependencies. A typical (shortened) example looks like this:
If you prefer the detector not to fail CI, set `failOnDeadCode = false` in the extension.
215
+
Set `failOnDeadCode = false` if you don’t want CI to fail.
172
216
173
-
## How it works (brief)
217
+
---
174
218
175
-
The plugin analyzes compiled class files, resources, and dependency references to determine which items are never referenced. Bytecode-level analysis makes detection reliable for compiled artifacts, but reflection or generated code may cause false positives.
219
+
## How it works
176
220
177
-
If you plan to use this in multi-module projects, run the detector in modules where compiled classes are available; otherwise, point to the compiled class directories if supported by the plugin configuration.
221
+
The plugin scans compiled class files, Android resources, and dependency references to detect unused elements. Reflection, generated code, or annotation processors may create false positives.
178
222
179
-
## Limitations & notes
223
+
---
180
224
181
-
* **Local variables** are not detected (Kotlin compiler may remove them in bytecode).
182
-
* **Reflection, dynamic calls, annotation processors, and dependency injection** can create false positives — code/resources/dependencies used only reflectively might appear unused.
183
-
* **Public API**: if your project exposes public functions/classes used by external consumers, set `keepPublicApi = true` to avoid false positives.
184
-
* Run the plugin after building the classes (`./gradlew classes`) so compiled output is present.
185
-
* `clearAllDeadCode` is currently a planned feature and not implemented.
225
+
## Limitations & Notes
186
226
187
-
## Contributing
227
+
* **Local variables** are ignored (removed by Kotlin/Java compiler).
0 commit comments