Skip to content
Analyze dependency usage in Android and Java projects, with a Gradle plugin
Kotlin Java Shell
Branch: master
Clone or download

Use cases

  1. Produces an "advice" report which indicates:
    • Unused dependencies which should be removed.
    • Declared dependencies which are on the wrong configuration (api vs implementation)
    • Transitively used dependencies which ought to be declared directly, and on which configuration.

This is printed to console in a narrative form, and also written to disk as JSON. The JSON output has three components (see the Advice model class):

  1. Dependency (identifier + resolved version)
  2. "fromConfiguration", which is the configuration on which the dependency is currently declared. Typically "api" or "implementation". If this field is not present, that means it is null and the dependency is transitive. It should be declared directly.
  3. "toConfiguration", which is the configuration on which the dependency should be declared. If this field is not present, that means it is null and the dependency should be removed.


  1. Android Gradle Plugin: tested to work with AGP 3.5.3, 3.6.0-rc01, and 4.0.0-alpha09 ( and projects only).
  2. Kotlin plugin: tested with Kotlin 1.3.x (specifically 1.3.5x-6x).
  3. Java Library Plugin: tested with the java-library plugin bundled with Gradle 5.6.4, 6.0.1, and 6.1.
  4. Gradle: this plugin is built with Gradle 6.1. It is tested against Gradle 5.6.4, 6.0.1, and 6.1.
  5. It works with Java, Kotlin, and Kapt. Both multi-module JVM and Android projects.

How to use

Add to your root project. See for instructions.

plugins {
    id("com.autonomousapps.dependency-analysis") version "${latest_version}"

Aggregate tasks

There will be a task on the root project with the name buildHealth. Running that task will execute all tasks in all projects, and then produce the advice report, aggregated across all subprojects. The path to this report will be printed to the console.

Customizing variants to analyze

If your Android project uses flavors or custom build types, you may wish to change the default variant that is analyzed. By default, this plugin will analyze the debug variant for Android, and the main source set for Java. To customize this, add the following to your root build.gradle[.kts]

dependencyAnalysis {
  setVariants("my", "custom", "variants")

If the plugin cannot find any variants by these names, it will first fallback to the defaults ("debug" and "main"), and then simply ignore the given subproject.

Per-project tasks

You can also run some tasks on individual projects.

For the advice report,

  1. Run the task ./gradlew my-project:adviceDebug, where "Debug" is the variant you're interested in. This will be "Main" for java-library projects (where the variant is based on source set name). It will produce advice reports in the build/reports/dependency-analysis/<variant>/ directory.

At this time, that is the only recommended task for end-users. If you are interested in the other tasks, please run ./gradlew tasks --group dependency-analysis or ./gradlew my-project:tasks --group dependency-analysis


This flowchart was built with Mermaid and is experimental. It's an attempt to provide some high-level documentation for potential contributors.


You can’t perform that action at this time.