-
Notifications
You must be signed in to change notification settings - Fork 132
/
build.gradle.kts
379 lines (321 loc) · 10.5 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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
import Build_gradle.MavenPomFile
import kotlinx.html.js.packageJson
import org.apache.tools.ant.taskdefs.condition.Os
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsSetupTask
/**
* This build script supports following parameters:
* -PversionTag - works together with "branch-build" profile and overrides "-SNAPSHOT" suffix of the version.
*/
plugins {
kotlin("multiplatform") version "1.7.10"
id("maven-publish")
id("signing")
}
group = "org.jetbrains.kotlinx"
version = "0.7.5-SNAPSHOT"
buildscript {
dependencies {
classpath("org.jetbrains.kotlinx:binary-compatibility-validator:0.11.0")
}
}
apply(plugin = "binary-compatibility-validator")
/**
* 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
}
}
}
create<MavenPublication>("kotlinx-html-assembly") {
artifactId = "kotlinx-html-assembly"
jar("jsWebJar") {
archiveBaseName by "${project.name}-assembly"
archiveClassifier by "webjar"
from("$buildDir/js/packages/${project.name}/kotlin/kotlinx-html-js.js")
into("META-INF/resources/webjars/${project.name}/${project.version}/")
}
}
}
}
repositories {
mavenCentral()
}
kotlin {
jvm {
mavenPublication {
groupId = group as String
pom { name by "${project.name}-jvm" }
javadocJar("jvmJavadocJar")
jar("jvmTestSourcesJar") {
archiveClassifier by "test-sources"
with(sourceSets["jvmTest"]) {
from(kotlin, resources)
}
}
}
}
js(BOTH) {
moduleName = project.name
compilations["main"].packageJson {
main = "kotlin/kotlinx-html-js.js"
name = "kotlinx-html-js"
}
compilations["main"].kotlinOptions.apply {
outputFile = "$buildDir/js/packages/${project.name}/kotlin/${project.name}-js.js"
moduleKind = "umd"
sourceMap = true
sourceMapEmbedSources = "always"
}
compilations["test"].kotlinOptions.apply {
moduleKind = "umd"
metaInfo = true
sourceMap = true
}
mavenPublication {
groupId = group as String
pom { name by "${project.name}-js" }
javadocJar("jsJavadocJar")
jar("jsTestSourcesJar") {
archiveClassifier by "test-sources"
with(sourceSets["jsTest"]) {
from(kotlin, resources)
}
}
}
}
mingwX64()
linuxX64()
iosX64()
iosArm64()
iosArm32()
iosSimulatorArm64()
watchosX86()
watchosX64()
watchosArm32()
watchosArm64()
watchosSimulatorArm64()
tvosX64()
tvosArm64()
tvosSimulatorArm64()
macosX64()
macosArm64()
metadata {
mavenPublication {
groupId = group as String
artifactId = "${project.name}-common"
pom {
name by "${project.name}-common"
}
javadocJar("commonJavadocJar")
jar("commonTestSourcesJar") {
archiveClassifier by "test-sources"
}
}
}
}
kotlin {
sourceSets {
commonMain {
dependencies {
implementation(kotlin("stdlib-common"))
}
}
val jsMain by getting {
dependencies {
implementation(kotlin("stdlib-js"))
}
}
val jsTest by getting {
dependencies {
implementation(kotlin("test-js"))
}
}
val jvmMain by getting {
dependencies {
implementation(kotlin("stdlib-jdk8"))
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit"))
/* Jackson is required to parse declarations.json. */
implementation("com.fasterxml.jackson.core:jackson-core:2.10.1")
implementation("com.fasterxml.jackson.core:jackson-databind:2.10.1")
}
}
val nativeMain by creating
val nativeTest by creating
val nativeTargets = listOf(
"mingwX64",
"linuxX64",
"iosX64",
"iosArm64",
"iosArm32",
"iosSimulatorArm64",
"watchosX86",
"watchosX64",
"watchosArm32",
"watchosArm64",
"watchosSimulatorArm64",
"tvosX64",
"tvosArm64",
"tvosSimulatorArm64",
"macosX64",
"macosArm64"
)
val commonMain by getting
nativeMain.dependsOn(commonMain)
nativeTargets.forEach { target ->
findByName("${target}Main")?.dependsOn(nativeMain)
findByName("${target}Test")?.dependsOn(nativeTest)
}
}
}
tasks.withType<Jar> {
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 org.gradle.util.GradleVersion.current()
)
}
}
tasks.register<Task>("generate") {
group = "source-generation"
description = "Generate tag-handling code using tags description."
doLast {
kotlinx.html.generate.generate(
"kotlinx.html",
"src/commonMain/kotlin/generated",
"src/jsMain/kotlin/generated"
)
}
}
tasks.register<Copy>("jsPackagePrepare") {
dependsOn("jsLegacyMainClasses")
tasks["assemble"].dependsOn(this)
group = "build"
description = "Assembles NPM package (result is placed into 'build/tmp/jsPackage')."
val baseTargetDir = "$buildDir/tmp/jsPackage"
from("README-JS.md")
from("$buildDir/js/packages/${project.name}/kotlin")
into(baseTargetDir)
rename("README-JS.md", "README.md")
doLast {
var npmVersion = version as String
if (npmVersion.endsWith("-SNAPSHOT")) {
npmVersion = npmVersion.replace("-SNAPSHOT", "-${System.currentTimeMillis()}")
}
val organization = when {
project.hasProperty("branch-build") -> "kotlinx-branch-build"
project.hasProperty("master-build") -> "kotlinx-master-build"
else -> null
}
File(baseTargetDir, "package.json").writeText(packageJson(npmVersion, organization))
file("$baseTargetDir/kotlinx-html-js").renameTo(File("$buildDir/js-module/kotlinx-html-js"))
}
}
publishing {
publications {
configureEach {
if (this is MavenPublication) {
pom.config()
}
}
}
}
typealias MavenPomFile = MavenPom
fun MavenPomFile.config(config: MavenPomFile.() -> Unit = {}) {
config()
url by "https://github.com/Kotlin/kotlinx.html"
name by "kotlinx.html"
description by "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 by "The Apache License, Version 2.0"
url by "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
scm {
connection by "scm:git:git@github.com:Kotlin/kotlinx.html.git"
url by "https://github.com/Kotlin/kotlinx.html"
tag by "HEAD"
}
developers {
developer {
name by "Sergey Mashkov"
organization by "JetBrains s.r.o."
roles to "developer"
}
developer {
name by "Anton Dmitriev"
organization by "JetBrains s.r.o."
roles to "developer"
}
}
}
tasks.withType<GenerateModuleMetadata> {
enabled = true
}
fun MavenPublication.jar(taskName: String, config: Action<Jar>) = artifact(tasks.create(taskName, Jar::class, config))
fun MavenPublication.javadocJar(taskName: String, config: Jar.() -> Unit = {}) = jar(taskName) {
archiveClassifier by "javadoc"
config()
}
infix fun <T> Property<T>.by(value: T) {
set(value)
}
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.nodejs.NodeJsRootPlugin> {
val nodeM1Version = "16.13.1"
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().nodeVersion = nodeM1Version
}
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
}