-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
81 lines (70 loc) · 2.17 KB
/
build.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
@file:Suppress("DSL_SCOPE_VIOLATION")
plugins {
base
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.spotless)
alias(libs.plugins.dokka)
alias(libs.plugins.arrow.gradle.nexus)
alias(libs.plugins.arrow.gradle.publish) apply false
alias(libs.plugins.semver.gradle)
}
allprojects {
group = property("project.group").toString()
}
fun isMultiplatformModule(project: Project): Boolean {
val kotlinPluginId = "libs.plugins.kotlin.multiplatform"
return project.buildFile.readText().contains(kotlinPluginId)
}
val multiPlatformModules = project.subprojects.filter { isMultiplatformModule(it) }.map { it.name }
enum class ModuleType {
MULTIPLATFORM,
SINGLEPLATFORM
}
fun Project.configureBuildAndTestTask(
taskName: String,
moduleType: ModuleType,
multiPlatformModules: List<String>
) {
val platform: String by extra
tasks.register(taskName) {
doLast {
val gradleCommand = getGradleCommand(platform)
project.exec {
commandLine(gradleCommand, "spotlessCheck")
}
project.exec {
when (moduleType) {
ModuleType.MULTIPLATFORM -> {
multiPlatformModules.forEach { module ->
commandLine(gradleCommand, ":$module:${platform}Test")
}
}
ModuleType.SINGLEPLATFORM -> {
commandLine(gradleCommand, "build", *buildExcludeOptions(multiPlatformModules))
}
}
}
}
}
}
fun Project.buildExcludeOptions(modules: List<String>): Array<String> {
return modules.flatMap { listOf("-x", ":$it:build") }.toTypedArray()
}
fun getGradleCommand(platform: String): String {
return if (platform == "mingwX64") {
"gradlew.bat"
} else {
"./gradlew"
}
}
configureBuildAndTestTask(
"buildAndTestMultip",
ModuleType.MULTIPLATFORM,
multiPlatformModules
)
configureBuildAndTestTask(
"buildAndTestSinglep",
ModuleType.SINGLEPLATFORM,
multiPlatformModules
)