Skip to content
Tony Robalik edited this page Apr 21, 2024 · 4 revisions

Main tasks

There are several primary tasks intended for use by end-users of the plugin. You may consider them the plugin’s "API", in a manner of speaking. They are listed below, although please note this list is often stale. For a complete list, run ./gradlew tasks --group dependency-analysis.

Build health

$ ./gradlew buildHealth

(or from the Gradle tasks pane in your IDE, under the "dependency-analysis" group)

This task will analyze every subproject (aka "module") in your project, including the root project, for dependency- and plugin-related issues, and produce several reports at build/reports/dependency-analysis/, the main one of which is advice.json. This report is generated in json format because it is intended for machine consumption and post-processing for advanced users. In addition to this main report, there are several others that are more human-readable, in the same directory.

Importantly, this task respects the severity setting, and so may fail if configured to do so.

Project health

$ ./gradlew :proj:projectHealth

projectHealth is the subproject- or module-analogue of buildHealth. It will emit advice for specific projects.

Importantly, this task respects the severity setting, and so may fail if configured to do so.

Reason

$ ./gradlew :proj:reason --id <identifier>

where <identifier> is a module identifier such as :some-proj or com.company:artifact (nb: without a version). You would execute this task to gain additional insight into the reason for some piece of advice. Consider the following example:

You run :proj:projectHealth and see

Existing dependencies which should be modified to be as indicated:
 api(project(":db")) (was implementation)
 api("androidx.appcompat:appcompat:1.1.0-rc01") (was implementation)

You want to understand why you are seeing this advice, so you run

$ ./gradlew :proj:reason --id :db

and you may see something like

> Task :proj:reason
You asked about the dependency :db. You have been advised to change this dependency to api from implementation.

Shortest path to :db from the current project:
:proj
\--- :db

Dependency :db provides the following:
- 15 classes
- 8 public constants

And this dependency is exposed as part of this project's ABI.

Or alternatively, you run

$ ./gradlew proj:reason --id androidx.appcompat:appcompat

with similar output. (Further improvements are planned for this feature.)

Fix Dependencies

This plugin supports the ability to auto-remediate, or auto-fix, the dependency-related issues it finds. It is based on a simplified grammar capable of parsing the most common Groovy and Kotlin DSL build script elements; this grammar does stumble over some things, such as if-statements.

$ ./gradlew proj:fixDependencies

Or, for only "safe" fixes:

$ ./gradlew proj:fixDependencies --upgrade