-
Notifications
You must be signed in to change notification settings - Fork 52
/
settings.gradle.kts
130 lines (111 loc) · 3.62 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
pluginManagement {
repositories {
gradlePluginPortal()
google()
}
}
plugins {
// See https://jmfayard.github.io/refreshVersions
id("de.fayard.refreshVersions") version "0.40.1"
}
rootProject.name = "BleGattCoroutines"
@Suppress("UnstableApiUsage")
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
google().ensureGroups(
"com.google.gms",
"com.google.test.platform",
"com.google.firebase",
"org.chromium.net",
"com.google.mlkit",
"com.google.testing.platform",
"com.google.devtools.ksp"
).ensureGroupsStartingWith(
"androidx.",
"com.android",
"com.google.android.",
"com.google.ar",
"android.arch"
)
}
}
include {
"core".withPrefix("blegattcoroutines-")
"genericaccess".withPrefix("blegattcoroutines-")
"samples" {
"app-mobile"()
"app-wear"()
"common"()
}
}
//region include DSL
class ModuleParentScope(
private val name: String,
private val parent: ModuleParentScope? = null
) {
fun String.withPrefix(
prefix: String,
block: (ModuleParentScope.() -> Unit)? = null
) {
invoke(gradleName = "$prefix$this", block)
}
operator fun String.invoke(
gradleName: String = this,
block: (ModuleParentScope.() -> Unit)? = null
) {
check(startsWith(':').not())
val moduleName = ":$this"
val projectName = "$parentalPath$moduleName"
include(projectName)
if (gradleName != this) {
project(moduleName).name = gradleName
}
block?.let { buildNode ->
ModuleParentScope(
name = moduleName,
parent = this@ModuleParentScope
).buildNode()
}
}
private val parentalPath: String =
generateSequence(this) { it.parent }
.map { it.name }.toList().reversed().joinToString("")
}
inline fun include(block: ModuleParentScope.() -> Unit) {
ModuleParentScope("").block()
}
//endregion
//region MavenArtifactRepository extensions
fun MavenArtifactRepository.ensureGroups(vararg group: String): MavenArtifactRepository = apply {
content { group.forEach { includeGroup(it) } }
}
fun MavenArtifactRepository.ensureGroupsByRegexp(vararg regexp: String): MavenArtifactRepository =
apply {
content { regexp.forEach { includeGroupByRegex(it) } }
}
fun MavenArtifactRepository.ensureGroupsStartingWith(vararg regexp: String): MavenArtifactRepository =
apply {
content { regexp.forEach { includeGroupByRegex(it.replace(".", "\\.") + ".*") } }
}
fun MavenArtifactRepository.ensureModules(vararg modules: String): MavenArtifactRepository = apply {
content { modules.forEach { includeModule(it.substringBefore(':'), it.substringAfter(':')) } }
}
fun MavenArtifactRepository.ensureModulesByRegexp(vararg regexp: String): MavenArtifactRepository =
apply {
content {
regexp.forEach { includeModuleByRegex(it.substringBefore(':'), it.substringAfter(':')) }
}
}
fun MavenArtifactRepository.ensureModulesStartingWith(vararg regexp: String): MavenArtifactRepository =
apply {
content {
regexp.forEach {
val groupRegex = it.substringBefore(':').replace(".", "\\.")
val moduleNameRegex = it.substringAfter(':').replace(".", "\\.") + ".*"
includeModuleByRegex(groupRegex, moduleNameRegex)
}
}
}
//endregion