-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle.kts
198 lines (175 loc) · 5.64 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* Copyright 2024 Ben Woodworth
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import kotlinx.validation.ExperimentalBCVApi
import org.gradle.kotlin.dsl.support.uppercaseFirstChar
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
import java.net.URL
plugins {
kotlin("multiplatform") version "2.0.20"
id("org.jetbrains.dokka") version "1.9.20"
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.16.3"
id("parameterize.library-conventions")
}
repositories {
mavenCentral()
}
apiValidation {
@OptIn(ExperimentalBCVApi::class)
klib {
enabled = true
}
}
@OptIn(ExperimentalWasmDsl::class)
kotlin {
explicitApi()
jvm {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
}
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
js {
browser()
nodejs()
}
linuxX64()
linuxArm64()
androidNativeArm32()
androidNativeArm64()
androidNativeX86()
androidNativeX64()
macosX64()
macosArm64()
iosSimulatorArm64()
iosX64()
watchosSimulatorArm64()
watchosX64()
watchosArm32()
watchosArm64()
tvosSimulatorArm64()
tvosX64()
tvosArm64()
iosArm64()
watchosDeviceArm64()
mingwX64()
wasmJs {
browser()
nodejs()
}
wasmWasi {
nodejs()
}
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
}
sourceSets {
all {
languageSettings.optIn("kotlin.contracts.ExperimentalContracts")
}
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting {
dependencies {
implementation("org.opentest4j:opentest4j:1.3.0")
}
}
}
}
val ciHostTargets = run {
val hostTargetPrefixes = mapOf(
"linux" to listOf("metadata", "jvm", "js", "linux", "android", "wasm"),
"macos" to listOf("macos", "ios", "watchos", "tvos"),
"windows" to listOf("mingw")
)
val hostTargets = hostTargetPrefixes.mapValues { (_, prefixes) ->
kotlin.targets.filter { target ->
prefixes.any { target.name.startsWith(it) }
}
}
val envCiHost = System.getenv("CI_HOST")
val osName = System.getProperty("os.name")
val host = when {
envCiHost != null -> envCiHost.also {
require(envCiHost in hostTargets) { "Invalid CI_HOST: $envCiHost. Must be one of: ${hostTargets.keys}" }
}
osName == "Linux" -> "linux"
osName == "Mac OS X" -> "macos"
osName.startsWith("Windows") -> "windows"
else -> error("Unable to determine CI Host for OS: $osName. CI_HOST env can be set instead.")
}
// Check for non-existent, unaccounted for, or double-counted targets
val allTargets = kotlin.targets.map { it.name }.sorted()
val groupedTargets = hostTargets.values.flatten().map { it.name }.sorted()
check(groupedTargets == allTargets) {
"Bad host target grouping.\n\tExpected: $allTargets\n\tActual: $groupedTargets"
}
hostTargets[host]!!.asSequence()
}
tasks.create("ciTest") {
ciHostTargets
.filterIsInstance<KotlinTargetWithTests<*, *>>()
.map { target -> "${target.name}Test" }
.forEach { targetTest ->
dependsOn(targetTest)
}
}
tasks.create("ciPublish") {
ciHostTargets
.map { it.name.uppercaseFirstChar() }
.map { if (it == "Metadata") "KotlinMultiplatform" else it }
.map { target -> "publish${target}PublicationToMavenRepository" }
.forEach { publishTarget ->
dependsOn(publishTarget)
}
}
tasks.withType<DokkaTask>().configureEach {
dokkaSourceSets.configureEach {
reportUndocumented = true
failOnWarning = true
val releaseVersionRef = version.toString()
.takeIf { version -> version.matches(Regex("""\d+\.\d+\.\d+""")) }
?.let { version -> "v$version" }
if (releaseVersionRef != null) {
sourceLink {
localDirectory = projectDir.resolve("src")
remoteUrl.set(URL("https://github.com/BenWoodworth/Parameterize/tree/$releaseVersionRef/src"))
remoteLineSuffix = "#L"
}
}
}
doLast {
layout.buildDirectory.asFileTree.asSequence()
.filter { it.isFile && it.extension == "html" }
.forEach { file ->
file.readText()
// Remove "ParameterizeConfiguration." prefix from link text for *Scope classes
.replace(Regex("""(?<=>)ParameterizeConfiguration\.(?=\w+Scope</a>)"""), "")
.let { file.writeText(it) }
}
}
}