How to get a list of all resolved dependencies for all projects?

In a multi-project build, I’d like to get a list of all resolved dependencies across all projects. I currently have this in my root build.gradle file:

projectDependencies = [:]
  allprojects {
    configurations.all { config ->
        config.incoming.afterResolve { resolution ->
            resolution.dependencies.each { dependency ->
                println dependency.name + ', ' + dependency.version
                projectDependencies[dependency.name] = dependency.version
            }
        }
    }
}
  println projectDependencies.size()

However, although I see “println” listing the dependencies, “projectDependencies” is empty (has a size of 0). I guess it has something to do with variable scoping, but I just cannot figure out what the correct syntax would be. Any ideas?

It’s not due to scoping but due to order of execution.

Code that is adding dependencies to your map is executed after dependencies are resolved but ‘println projectDependencies.size()’ executes immediately.

Doh, right :slight_smile: I also figure I should use

ext.projectDependencies = [:]

instead.