Detect unused and misused dependencies
The Dependency Analysis Gradle Plugin (DAGP, née Dependency Analysis Android Gradle Plugin) detects the following:
-
Unused dependencies.
-
Used transitive dependencies (which you may want to declare directly).
-
Dependencies declared on the wrong configuration (
api
vsimplementation
vscompileOnly
, etc.).
As a side effect, the plugin can also tell you your project’s ABI, and produces graphviz files representing various views of your dependency graph, among other things. These side effects are currently mostly undocumented internal behaviors, but they may be interesting for some advanced users.
Build health
In addition to the dependency-related advice (see above), DAGP provides other advice to help maintain your "build health." This includes the detection of:
-
Unnecessary plugins (currently only
kapt
). -
Subprojects ("modules") that unnecessarily use the Android plugin, and could instead by "normal" JVM libraries.
Compatibilities
Please see the wiki for information on the versions of Gradle, the Android Gradle Plugin, etc., that this plugin is compatible with.
Add to your project and use
For detailed instructions, see the wiki.
The simplest approach is to add the following:
plugins {
id("com.autonomousapps.dependency-analysis") version "<<latest_version>>"
}
For a quick start, just run the following:
./gradlew buildHealth
More advanced usage
Project Health
You can also run the analysis against individual modules with the projectHealth
task. For example:
./gradlew app:projectHealth
Reason
You may be curious why the plugin is emitting (or not emitting) advice regarding some dependency. You can ask it why:
./gradlew lib:reason --id com.squareup.okio:okio:2.2.2 (1) > Task :lib:reason ---------------------------------------- You asked about the dependency 'com.squareup.okio:okio:2.2.2'. There is no advice regarding this dependency. ---------------------------------------- Shortest path from :lib to com.squareup.okio:okio:2.2.2: :lib \--- com.squareup.okio:okio:2.2.2 Source: main ------------ * Exposes class okio.BufferedSource (implies api).
-
The version string is optional.
Basic configuration
For detailed information on how to configure the plugin, see the wiki.
To configure the plugin, use the dependencyAnalysis
extension.
dependencyAnalysis {
// configuration goes here
}
Publications
The following is a list of articles / blog posts that have been published discussing this plugin:
…​with more to come :)
This plugin has also been featured in these newsletters:
Podcast episodes about this plugin could be found here:
Youtube videos about this plugin: