Jay Taylor's notes

back to listing index

Gradle tricks – display dependencies for all subprojects in multi-project build

[web search]
Original source (solidsoft.wordpress.com)
Tags: howto dependencies gradle solidsoft.wordpress.com
Clipped on: 2019-10-04

Solid Soft

Working code is not enough

Gradle tricks – display dependencies for all subprojects in multi-project build

Posted: 2014-11-13 in Tricks & Tips
Tags: , ,

gradle dependencies allows to display dependencies in your project printed as pretty ascii tree. Unfortunately it does not work well for submodules in multi-project build. I was not able to find satisfactory solution on the web, so after worked out my own that blog post arose.

Multiple subprojects

For multi-project builds gradle dependencies called in the root directory unexpectedly displays no dependencies:

  • Image (Asset 3/13) alt= If gradle is configured to run tasks in parallel, this wil make the output useless, because it interweaves output from the different subprojects.
    I added this to solve it:
    “`
    // Create a chain of dependencies between all sub project’s “allDeps” tasks, so that the output is linear
    // even when we run gradle in default “–parallel” mode.
    def allSubProjects = subprojects as List
    for (def index = 1; index < allSubProjects.size; ++index) {
    allSubProjects[index].tasks.allDeps.dependsOn allSubProjects[index – 1].tasks.allDeps
    }
    “`

    • Thanks for sharing. That in fact could be some problem, but for most of the projects I worked with it was doable to just wait a little bit longer executing just that one task. However then, you need to remember to disable the parallel mode :).

      Btw, what Gradle version do you use? I believe in one of the Gradle versions released this year I have seen an improvement which was sorting out the console output in the parallel mode. Therefore, maybe it is already fixed out-of-box in 4.10?

  • Leave a Reply

    .