-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
272 lines (237 loc) · 8.47 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
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.dokka.gradle.DokkaTask
import java.net.URL
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
repositories {
mavenCentral()
google()
}
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.serialization)
alias(libs.plugins.dokka)
alias(libs.plugins.sonarqube)
alias(libs.plugins.kover)
alias(libs.plugins.detekt)
alias(libs.plugins.ktlint)
id("maven-publish")
id("signing")
}
val buildNumber: String get() = System.getenv("BUILD_NUMBER") ?: ""
val isSnapshot: Boolean get() = System.getProperty("snapshot") != null
version = "$version${if (isSnapshot) "-SNAPSHOT" else ""}"
kotlin {
explicitApi()
jvm {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
}
}
js {
browser {
testTask {
useKarma {
useChromeHeadless()
}
}
}
nodejs()
}
wasmJs {
browser {
testTask {
useKarma {
useChromeHeadless()
}
}
}
nodejs()
}
wasmWasi {
nodejs()
}
macosX64()
macosArm64()
iosX64()
iosArm64()
iosSimulatorArm64()
watchosArm32()
watchosArm64()
watchosX64()
watchosSimulatorArm64()
watchosDeviceArm64()
tvosArm64()
tvosX64()
tvosSimulatorArm64()
mingwX64()
linuxX64()
linuxArm64()
linuxArm32Hfp()
androidNativeArm32()
androidNativeArm64()
androidNativeX86()
androidNativeX64()
applyDefaultHierarchyTemplate()
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.serialization.core)
}
}
val commonTest by getting {
dependencies {
implementation(libs.kotlin.test)
implementation(libs.serialization.json)
}
}
}
}
tasks.getByName<DokkaTask>("dokkaHtml") {
outputDirectory.set(file(buildDir.resolve("dokka")))
dokkaSourceSets {
configureEach {
includes.from("Module.md")
samples.from("src/commonTest/kotlin/io/github/z4kn4fein/semver/samples")
sourceLink {
localDirectory.set(file("src/commonMain/kotlin"))
remoteUrl.set(URL("https://github.com/z4kn4fein/kotlin-semver/blob/master/src/commonMain/kotlin"))
remoteLineSuffix.set("#L")
}
}
}
val json = """{ "customStyleSheets": ["${file(project.projectDir.resolve("assets/custom.css"))}"] }"""
pluginsMapConfiguration.set(mapOf("org.jetbrains.dokka.base.DokkaBase" to json.replace("\\", "/")))
doLast {
outputDirectory.getAsFileTree().getFiles()
.filter { it.extension == "html" }
.forEach { file ->
var text = file.readText()
if (!(file.parent?.endsWith("dokka") ?: false)) {
text = text.replace(
"<script type=\"text/javascript\" src=\"https://unpkg.com/kotlin-playground@1/dist/playground.min.js\" async=\"async\"></script>",
"<script type=\"text/javascript\" src=\"https://unpkg.com/kotlin-playground@1\" data-selector=\"code\" " +
"data-server=\"https://pcsajtai-kotlin-compiler.onrender.com\"></script>"
)
}
file.writeText(
text.replace(
"<button class=\"navigation-controls--btn navigation-controls--theme\" id=\"theme-toggle-button\" type=\"button\">switch theme</button>",
"<a href=\"https://github.com/z4kn4fein/kotlin-semver\" target=\"_blank\" rel=\"noopener\" class=\"gh-link\"><i class=\"fa fa-github\"></i> <span class=\"repo-name\">" +
"z4kn4fein/kotlin-semver</span></a><button class=\"navigation-controls--btn navigation-controls--theme\" id=\"theme-toggle-button\" type=\"button\">switch theme</button>"
).replace(
"styles/custom.css\" rel=\"Stylesheet\">",
"styles/custom.css\" rel=\"Stylesheet\">" +
"<link href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css\" rel=\"Stylesheet\">"
)
)
}
}
}
val javadocJar =
tasks.register<Jar>("javadocJar") {
archiveClassifier.set("javadoc")
dependsOn("dokkaHtml")
from(buildDir.resolve("dokka"))
}
detekt {
buildUponDefaultConfig = true
parallel = true
isIgnoreFailures = true
}
ktlint {
filter {
exclude { element -> element.file.path.contains("build.gradle.kts") }
}
}
tasks.withType<Detekt>().configureEach {
setSource(project.files(project.projectDir.resolve("src/commonMain")))
include("**/*.kt")
reports {
html.required.set(true)
xml.required.set(true)
txt.required.set(true)
sarif.required.set(true)
}
}
rootProject.the<NodeJsRootExtension>().apply {
nodeVersion = "22.0.0-nightly202404032241e8c5b3"
nodeDownloadBaseUrl = "https://nodejs.org/download/nightly"
}
tasks.withType<KotlinNpmInstallTask>().configureEach {
args.add("--ignore-engines")
}
sonarqube {
properties {
property("sonar.projectKey", "z4kn4fein_kotlin-semver")
property("sonar.projectName", "kotlin-semver")
property("sonar.projectVersion", "$version-$buildNumber")
property("sonar.organization", "z4kn4fein")
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.sources", "src/commonMain/kotlin/io/github/z4kn4fein/semver")
property("sonar.tests", "src/commonTest/kotlin/io/github/z4kn4fein/semver")
property("sonar.kotlin.detekt.reportPaths", buildDir.resolve("reports/detekt/detekt.xml"))
property("sonar.coverage.jacoco.xmlReportPaths", buildDir.resolve("reports/kover/report.xml"))
}
}
publishing {
repositories {
maven {
name = "oss"
val releasesRepoUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
val snapshotsRepoUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
url = if (isSnapshot) snapshotsRepoUrl else releasesRepoUrl
credentials {
username = System.getenv("SONATYPE_USERNAME")
password = System.getenv("SONATYPE_PASSWORD")
}
}
}
publications.withType<MavenPublication> {
artifact(javadocJar.get())
pom {
name.set("Kotlin Semantic Versioning")
description.set(
"Semantic Versioning library for Kotlin Multiplatform. It implements the full semantic version " +
"2.0.0 specification and provides the ability to parse, compare, and increment semantic " +
"versions along with validation against constraints.",
)
url.set("https://z4kn4fein.github.io/kotlin-semver")
issueManagement {
system.set("GitHub Issues")
url.set("https://github.com/z4kn4fein/kotlin-semver/issues")
}
ciManagement {
system.set("GitHub Actions")
url.set("https://github.com/z4kn4fein/kotlin-semver/actions")
}
licenses {
license {
name.set("MIT License")
url.set("https://raw.githubusercontent.com/z4kn4fein/kotlin-semver/main/LICENSE")
}
}
developers {
developer {
id.set("z4kn4fein")
name.set("Peter Csajtai")
email.set("[email protected]")
}
}
scm {
url.set("https://github.com/z4kn4fein/kotlin-semver")
}
}
}
}
signing {
val signingKey = System.getenv("SIGNING_KEY") ?: ""
val signingPassphrase = System.getenv("SIGNING_PASSPHRASE") ?: ""
if (signingKey.isNotEmpty() && signingPassphrase.isNotEmpty()) {
useInMemoryPgpKeys(signingKey, signingPassphrase)
sign(publishing.publications)
}
}
tasks.withType<AbstractPublishToMaven>().configureEach {
dependsOn(tasks.withType<Sign>())
}