Last active
February 20, 2026 19:40
-
-
Save mrenouf/7a8107d154f975cfc5c46b37bba18169 to your computer and use it in GitHub Desktop.
Dump grade submodule dependency graph as Graphiz
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
| fun dependencyGraph(project: Project): Map<String, List<String>> { | |
| fun Dependency.qualifiedName() = toString().substringAfter("'").substringBefore("'") | |
| return project.configurations.flatMap { cfg -> | |
| cfg.dependencies | |
| .filter { project.path != it.qualifiedName() } | |
| .filter { dep -> | |
| dep.toString().startsWith("project") || | |
| dep.toString().startsWith("DefaultProjectDependency") | |
| } | |
| }.distinctBy { it.qualifiedName() } | |
| .map { dep -> | |
| project.path to dep.qualifiedName() | |
| } | |
| .groupToLists() | |
| } | |
| fun <A, B> List<Pair<A, B>>.groupToLists(): Map<A, List<B>> { | |
| return groupingBy { it.first } | |
| .aggregate { _, accumulator, element, _ -> | |
| (accumulator ?: emptyList()) + (element.second) | |
| } | |
| } | |
| fun projectDependencyGraph(project: Project): Map<String, List<String>> = buildMap { | |
| putAll(dependencyGraph(project)) | |
| project.subprojects.forEach { subproject -> | |
| putAll(projectDependencyGraph(subproject)) | |
| } | |
| } | |
| rootProject.tasks.register("deps") { | |
| group = "verification" | |
| println(rootProject.group) | |
| println("digraph {") | |
| val graph = projectDependencyGraph(rootProject).toSortedMap() | |
| println(""" node [shape=box, style="rounded,filled", fillcolor="#e8e8e8", fontname="Helvetica"]""") | |
| println(""" edge [color="#666666"]""") | |
| graph.keys.distinct().sorted().map { path -> | |
| path.split(':').getOrNull(1) to path | |
| }.filter { it.first != null }.groupToLists().forEach { (group, projects) -> | |
| println(""" subgraph cluster_${group?.replace('-', '_')} {""") | |
| println(""" label = "$group";""") | |
| println(""" style="rounded,dashed"""") | |
| println(""" fontname="Helvetica-Bold""") | |
| projects.forEach { project -> | |
| println(""" "$project";""") | |
| } | |
| println(" }") | |
| } | |
| graph.entries.forEach { (project, deps) -> | |
| deps.sorted().forEach { dep -> | |
| println(" \"$project\" -> \"$dep\"") | |
| } | |
| } | |
| println("}") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment