forked from xebia-functional/xef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
67 lines (54 loc) · 2.26 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
@file:Suppress("DSL_SCOPE_VIOLATION")
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
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 Project.configureBuildAndTestTask(taskName: String, moduleType: ModulePlatformType) {
val platform: String by extra
val multiPlatformModules = project.subprojects.filter { isMultiPlatformModule(it) }.map { it.name }
tasks.register(taskName) {
val gradleCommand = getGradleCommand(platform)
doLast {
when (moduleType) {
ModulePlatformType.SINGLE -> {
project.exec { commandLine(gradleCommand, ":xef-openai-client-generator:openaiClientGenerate") }
val excludedModules = includeOrNotModulesToCommand(multiPlatformModules, platform, false)
project.exec { commandLine(gradleCommand, "build", *excludedModules) }
}
ModulePlatformType.MULTI -> {
project.exec { commandLine(gradleCommand, ":xef-openai-client-generator:openaiClientGenerate") }
val includedModules = includeOrNotModulesToCommand(multiPlatformModules, platform, true)
project.exec { commandLine(gradleCommand, *includedModules) }
}
}
}
}
}
enum class ModulePlatformType { SINGLE, MULTI }
fun isMultiPlatformModule(project: Project): Boolean {
val kotlinPluginId = "libs.plugins.kotlin.multiplatform"
return project.buildFile.readText().contains(kotlinPluginId)
}
fun includeOrNotModulesToCommand(modules: List<String>, platform: String, include: Boolean): Array<String> {
return modules.flatMap {
when (include) {
true -> listOf(":$it:${platform}Test")
false -> listOf("-x", ":$it:build")
}
}.toTypedArray()
}
fun getGradleCommand(platform: String): String {
return if (platform == "mingwX64") "gradlew.bat" else "./gradlew"
}
configureBuildAndTestTask("buildAndTestMultip", ModulePlatformType.MULTI)
configureBuildAndTestTask("buildAndTestSinglep", ModulePlatformType.SINGLE)