-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
56 lines (49 loc) · 2.38 KB
/
build.gradle.kts
File metadata and controls
56 lines (49 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import groovy.json.JsonOutput
plugins {
// this is necessary to avoid the plugins to be loaded multiple times
// in each subproject's classloader
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.composeMultiplatform) apply false
alias(libs.plugins.composeCompiler) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.androidKotlinMultiplatformLibrary) apply false
alias(libs.plugins.androidLint) apply false
alias(libs.plugins.cocoapods) apply false
id("com.google.gms.google-services") version "4.4.4" apply false
}
tasks.register("exportModuleDeps") {
doLast {
val allModuleNames = rootProject.subprojects.map { it.name }.toSet()
val directDependencies = mutableMapOf<String, MutableSet<String>>()
rootProject.subprojects.forEach { project ->
val projectDeps = mutableSetOf<String>()
project.configurations
.matching { it.name.contains("implementation", ignoreCase = true) }
.forEach { configuration ->
configuration.dependencies.forEach { dependency ->
if (dependency is ProjectDependency && allModuleNames.contains(dependency.dependencyProject.name)) {
projectDeps.add(dependency.dependencyProject.name)
}
}
}
directDependencies[project.name] = projectDeps
}
val reverseDependencies = mutableMapOf<String, MutableSet<String>>()
directDependencies.keys.forEach { module -> reverseDependencies[module] = mutableSetOf() }
directDependencies.forEach { (module, deps) ->
deps.forEach { dep -> reverseDependencies[dep]?.add(module) }
}
fun collectAllDependents(
module: String,
visited: MutableSet<String> = mutableSetOf()
): Set<String> {
if (!visited.add(module)) return emptySet()
val directDependents = reverseDependencies[module] ?: emptySet()
return directDependents + directDependents.flatMap { collectAllDependents(it, visited) }
}
val modulesWithDependents =
directDependencies.keys.associateWith { collectAllDependents(it) }
println(JsonOutput.toJson(modulesWithDependents))
}
}