Configure Gradle to Allow Listing All Subproject Dependencies
Every so often, I need to list the dependency tree for my Gradle projects, which doesn't work out-of-the-box when using subprojects. I bookmarked the great post Gradle tricks β display dependencies for all subprojects in multi-project build as I so regularly come back to it, as it solves the issue for us.
However, I wondered if there was a better way to do this, as I didn't want to commit this task into each project, but I also didn't have to keep locally adding it to each project, and then removing it before committing.
Fortunately, we can follow Configure Gradle to Configure Tasks Globally with an initscript and create a file i.e. ~/.gradle/init.d/allDeps.gradle
:
projectsEvaluated {
rootProject.allprojects {
if (!tasks.findByName('allDeps')) {
task allDeps(type: DependencyReportTask) {}
}
}
}
This will then allow you to run gradle allDeps
in any of your projects and get your full dependency tree, only if if that task isn't already defined (so we don't overwrite something useful).