I wanted to find unused dependencies in my project. Is there a feature for this in Gradle, like in Maven?
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