Skip to content

Instantly share code, notes, and snippets.

@nikialeksey
Created June 28, 2018 03:44
Show Gist options
  • Save nikialeksey/7cefae6b3104ce9a2c765197343bc436 to your computer and use it in GitHub Desktop.
Save nikialeksey/7cefae6b3104ce9a2c765197343bc436 to your computer and use it in GitHub Desktop.
Gradle: multi-project dependency graph (supports depth > 2, supports gradle 4.4+)
// Inspired by https://gist.github.com/tzachz/419478fc8b009e953f5e5dc39f3f3a2a
// Task creates a .dot file with all inter-module dependencies
// Supports any depth of nested modules
task moduleDependencyReport {
doLast {
def file = new File("project-dependencies.dot")
file.delete()
file << "strict digraph {\n"
file << "splines=ortho\n"
printDeps(file, rootProject)
file << "}\n"
}
}
// recursively print dependencies to file and move on to child projects
def printDeps(file, project) {
project.configurations
.collectMany { it.allDependencies }
.findAll { it instanceof ProjectDependency }
.each { to -> file << ("\"${project.name}\" -> \"${to.name}\"\n")}
project.childProjects.each { name, childProject -> printDeps(file, childProject) }
}
@hokkun-dayo
Copy link

Hello @nikialeksey
I think it might be better to insert Collections#unique after findAll because the achieved file will be much simpler :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment