Created
December 22, 2020 18:35
-
-
Save umnagendra/7acb28d1ea674dd5e2ede41d9d639d13 to your computer and use it in GitHub Desktop.
Gradle - Generate Graphviz / PlantUML dependency graph among multi-module projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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