Skip to content

Instantly share code, notes, and snippets.

@umnagendra
Created December 22, 2020 18:35
Show Gist options
  • Select an option

  • Save umnagendra/7acb28d1ea674dd5e2ede41d9d639d13 to your computer and use it in GitHub Desktop.

Select an option

Save umnagendra/7acb28d1ea674dd5e2ede41d9d639d13 to your computer and use it in GitHub Desktop.
Gradle - Generate Graphviz / PlantUML dependency graph among multi-module projects
# Inspired by https://gist.github.com/tzachz/419478fc8b009e953f5e5dc39f3f3a2a
## INSTRUCTIONS
#
# 1. Place this in build.gradle of root project
# 2. Execute `gradle projectDependencyGraph` - A new file called `project-dependencies.puml` will be generated in the current directory
# 3. Render the PUML file to get a directed graph illustrating dependencies among project modules under the root project
#
##
task projectDependencyGraph {
doLast {
def file = new File("project-dependencies.puml")
file.delete()
file << "@startuml"
file << "digraph projectDependencyGraph {\n"
file << "splines=polyline\n"
file << "ranksep=2.5\n"
file << "rankdir=BT\n"
findAndAddProjectDependencies(file, rootProject)
file << "}\n"
file << "@enduml"
}
}
def findAndAddProjectDependencies(file, project) {
project.configurations.compile.dependencies
.matching { it in ProjectDependency }
.each { to -> file << ("\"${project.name}\" -> \"${to.name}\"\n")}
project.childProjects.each { child -> findAndAddProjectDependencies(file, child.value) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment