To get started with it, add the following two things to your Gradle build script. Once those are in place, run gradle analyze . If there are unused dependencies, you'll get a build failure that shows output similar to the text below, plus a list of the unused dependencies (both declared and transitive).
Generally, you can refresh dependencies in your cache with the command line option --refresh-dependencies. You can also delete the cached files under ~/. gradle/caches . With the next build Gradle would attempt to download them again.
In June, 2017, they have released the
4.0.0 version
and renamed the root project name"gradle-lint-plugin"
to"nebula-lint-plugin"
. They have also added Android support to unused-dependency.
In May 2016 Gradle has implemented the Gradle lint plugin for finding and removing unwanted dependency
The Gradle Lint plugin is a pluggable and configurable linter tool for identifying and reporting on patterns of misuse or deprecations in Gradle scripts and related files.
This plugin has various rules. Unused Dependency Rule is one of them. It has three specific characteristics.
To apply the rule, add:
gradleLint.rules += 'unused-dependency'
Details of Unused Dependency Rule is given in the last part.
To apply the Gradle lint plugin:
buildscript { repositories { jcenter() } }
plugins {
id 'nebula.lint' version '0.30.2'
}
Alternatively:
buildscript {
repositories { jcenter() }
dependencies {
classpath 'com.netflix.nebula:gradle-lint-plugin:latest.release'
}
}
apply plugin: 'nebula.lint'
Define which rules you would like to lint against:
gradleLint.rules = ['all-dependency'] // Add as many rules here as you'd like
For an enterprise build, we recommend defining the lint rules in a init.gradle script or in a Gradle script that is included via the Gradle apply from mechanism.
For multimodule projects, we recommend applying the plugin in an allprojects
block:
allprojects {
apply plugin: 'nebula.lint'
gradleLint.rules = ['all-dependency'] // Add as many rules here as you'd like
}
To apply the rule, add:
gradleLint.rules += 'unused-dependency'
The rule inspects compiled binaries emanating from your project's source sets looking for class references and matches those references to the dependencies that you have declared in your dependencies block.
For your kind information, I want to share about previous plugins
But its latest version 1.0.3 is created 23 December 2014. After that there aren't any updates.
N.B: Many of our engineers are being confused about this plugin as they updated only the version number, nothing else.
The project mentioned in the earlier answers seem to be dead. I use gradle-dependency-analyze. Setup is simple:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'ca.cutterslade.gradle:gradle-dependency-analyze:1.0.3'
}
}
apply plugin: 'ca.cutterslade.analyze'
Then do:
$ gradle analyzeDependencies
I've had a lot of luck using the Gradle Dependency Analysis Plugin. To get started with it, add the following two things to your Gradle build script.
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.github.nullstress:DependencyAnalysisPlugin:1.0.3"
}
}
and
apply plugin: "dependencyAnalysis"
Once those are in place, run gradle analyze
. If there are unused dependencies, you'll get a build failure that shows output similar to the text below, plus a list of the unused dependencies (both declared and transitive). The build failure is really handy if you want to enforce that there should be no unused dependencies via a CI build.
:foo:analyze FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':foo:analyze'.
> The project has unused declared artifacts
I just learned about this one: https://plugins.gradle.org/plugin/com.autonomousapps.dependency-analysis
Github
From the looks it is under active development, but I haven't tested it yet.
Edit: Actually its pretty awesome, it provides lots of advises (e.g. whether to use api vs implementation)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With