Configure Gradle to Allow Listing All Subproject Dependencies

Featured image for sharing metadata for article

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).

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #gradle #java.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.