-
Notifications
You must be signed in to change notification settings - Fork 133
/
build.gradle.kts
278 lines (242 loc) · 7.13 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
/**
* This build script supports the following parameters:
* -PversionTag - works together with "branch-build" profile and overrides "-SNAPSHOT" suffix of the version.
*/
plugins {
kotlin("multiplatform") version "2.0.20"
id("maven-publish")
id("signing")
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2"
}
group = "org.jetbrains.kotlinx"
version = "0.11.0"
/**
* If "release" profile is used the "-SNAPSHOT" suffix of the version is removed.
*/
if (hasProperty("release")) {
val versionString = version as String
if (versionString.endsWith("-SNAPSHOT")) {
version = versionString.replace("-SNAPSHOT", "")
}
}
/**
* Handler of "versionTag" property.
* Required to support Maven and NPM repositories that doesn't support "-SNAPSHOT" versions. To build and publish
* artifacts with specific version run "./gradlew -PversionTag=my-tag" and the final version will be "0.6.13-my-tag".
*/
if (hasProperty("versionTag")) {
val versionString = version as String
val versionTag = properties["versionTag"]
if (versionString.endsWith("-SNAPSHOT")) {
version = versionString.replace("-SNAPSHOT", "-$versionTag")
logger.lifecycle("Project will be built with version '$version'.")
} else {
error("Could not apply 'versionTag' together with non-snapshot version.")
}
}
if (hasProperty("releaseVersion")) {
version = properties["releaseVersion"] as String
}
val publishingUser = System.getenv("PUBLISHING_USER")
val publishingPassword = System.getenv("PUBLISHING_PASSWORD")
val publishingUrl = System.getenv("PUBLISHING_URL")
publishing {
publications {
repositories {
if (publishingUser == null) return@repositories
maven {
url = uri(publishingUrl)
credentials {
username = publishingUser
password = publishingPassword
}
}
}
}
}
repositories {
mavenCentral()
}
val emptyJar = tasks.register<org.gradle.jvm.tasks.Jar>("emptyJar") {
archiveAppendix.set("empty")
}
kotlin {
jvm {
mavenPublication {
groupId = group as String
pom { name = "${project.name}-jvm" }
artifact(emptyJar) {
classifier = "javadoc"
}
}
}
js {
moduleName = project.name
browser {
testTask {
useKarma {
useChromeHeadless()
}
}
}
mavenPublication {
groupId = group as String
pom { name = "${project.name}-js" }
}
}
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
moduleName = project.name
browser()
mavenPublication {
groupId = group as String
pom { name = "${project.name}-wasm-js" }
}
}
@OptIn(ExperimentalWasmDsl::class)
wasmWasi {
nodejs()
mavenPublication {
groupId = group as String
pom { name = "${project.name}-wasm-wasi" }
}
}
mingwX64()
linuxX64()
linuxArm64()
iosX64()
iosArm64()
iosSimulatorArm64()
watchosX64()
watchosArm32()
watchosArm64()
watchosSimulatorArm64()
watchosDeviceArm64()
tvosX64()
tvosArm64()
tvosSimulatorArm64()
macosX64()
macosArm64()
androidNativeArm32()
androidNativeArm64()
androidNativeX86()
androidNativeX64()
@OptIn(ExperimentalKotlinGradlePluginApi::class)
applyDefaultHierarchyTemplate {
common {
group("jsCommon") {
withJs()
withWasmJs()
}
}
}
metadata {
mavenPublication {
groupId = group as String
artifactId = "${project.name}-common"
pom {
name = "${project.name}-common"
}
}
}
}
kotlin {
jvmToolchain(8)
sourceSets {
commonTest {
dependencies {
implementation(kotlin("test"))
}
}
}
}
tasks.withType<Jar>().configureEach {
manifest {
attributes += sortedMapOf(
"Built-By" to System.getProperty("user.name"),
"Build-Jdk" to System.getProperty("java.version"),
"Implementation-Vendor" to "JetBrains s.r.o.",
"Implementation-Version" to archiveVersion.get(),
"Created-By" to GradleVersion.current()
)
}
}
tasks.register<Task>("generate") {
group = "source-generation"
description = "Generate tag-handling code using tags description."
doLast {
kotlinx.html.generate.generate(
pkg = "kotlinx.html",
todir = "src/commonMain/kotlin/generated",
jsdir = "src/jsMain/kotlin/generated",
wasmJsDir = "src/wasmJsMain/kotlin/generated"
)
kotlinx.html.generate.generateJsTagTests(
jsdir = "src/jsTest/kotlin/generated",
wasmJsDir = "src/wasmJsTest/kotlin/generated",
)
}
}
publishing {
publications {
configureEach {
if (this is MavenPublication) {
pom.config()
}
}
}
}
typealias MavenPomFile = MavenPom
fun MavenPomFile.config(config: MavenPomFile.() -> Unit = {}) {
config()
url = "https://github.com/Kotlin/kotlinx.html"
name = "kotlinx.html"
description = "A kotlinx.html library provides DSL to build HTML to Writer/Appendable or DOM at JVM and browser (or other JavaScript engine) for better Kotlin programming for Web."
licenses {
license {
name = "The Apache License, Version 2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
scm {
connection = "scm:git:[email protected]:Kotlin/kotlinx.html.git"
url = "https://github.com/Kotlin/kotlinx.html"
tag = "HEAD"
}
developers {
developer {
name = "Sergey Mashkov"
organization = "JetBrains s.r.o."
roles to "developer"
}
developer {
name = "Anton Dmitriev"
organization = "JetBrains s.r.o."
roles to "developer"
}
}
}
tasks.withType<GenerateModuleMetadata>().configureEach {
enabled = true
}
val signingKey = System.getenv("SIGN_KEY_ID")
val signingKeyPassphrase = System.getenv("SIGN_KEY_PASSPHRASE")
if (!signingKey.isNullOrBlank()) {
project.ext["signing.gnupg.keyName"] = signingKey
project.ext["signing.gnupg.passphrase"] = signingKeyPassphrase
signing {
useGpgCmd()
sign(publishing.publications)
}
}
rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin::class.java) {
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().ignoreScripts = false
}
tasks.named("jsBrowserTest") {
dependsOn("wasmJsTestTestDevelopmentExecutableCompileSync")
}
tasks.named("wasmJsBrowserTest") {
dependsOn("jsTestTestDevelopmentExecutableCompileSync")
}