-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.gradle.kts
75 lines (66 loc) · 1.96 KB
/
settings.gradle.kts
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pluginManagement {
includeBuild("build-logic")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google {
content {
includeGroupByRegex("com.android.*")
includeGroupByRegex("androidx.*")
includeGroupByRegex("com.google.android.*")
}
}
mavenCentral()
}
}
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
// Automatically detect modules.
ModuleDetector.modules(rootDir).forEach { module ->
include(module)
}
private object ModuleDetector {
fun modules(rootDir: File) : List<String> {
return rootDir.listDirs().flatMap { dir ->
findModules(parent = "", dir = dir)
}
}
private fun findModules(parent: String, dir: File): List<String> {
if (dir.isDirectory.not() || dir.isProject()) {
return emptyList()
}
val current: String = parent + ":" + dir.name
return if (dir.isModule()) {
println("include '$current'")
listOf(current)
} else {
dir.listDirs().flatMap { subDir ->
findModules(parent = current, dir = subDir)
}
}
}
private fun File.isProject(): Boolean {
if (isDirectory.not()) {
return false
}
return listFiles().orEmpty().any {
it.isFile && (it.name == "settings.gradle" || it.name == "settings.gradle.kts")
}
}
private fun File.isModule(): Boolean {
if (isDirectory.not()) {
return false
}
return listFiles().orEmpty().any {
it.isFile && (it.name == "build.gradle" || it.name == "build.gradle.kts")
}
}
private fun File.listDirs(): List<File> {
return listFiles().orEmpty().filter { it.isDirectory }
}
}