-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
build.gradle.kts
271 lines (248 loc) · 8.88 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
import aQute.bnd.gradle.BundleTaskExtension
import com.diffplug.gradle.spotless.SpotlessExtension
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import groovy.util.Node
import groovy.util.NodeList
import java.nio.charset.StandardCharsets
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED
import org.gradle.api.tasks.testing.logging.TestLogEvent.STARTED
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("build-support").apply(false)
}
buildscript {
dependencies {
classpath(libs.android.gradle.plugin)
classpath(libs.burst.gradle.plugin)
classpath(libs.dokka)
classpath(libs.jmh.gradle.plugin)
classpath(libs.binaryCompatibilityValidator)
classpath(libs.spotless)
classpath(libs.bnd)
classpath(libs.vanniktech.publish.plugin)
}
repositories {
mavenCentral()
gradlePluginPortal()
google()
}
}
apply(plugin = "com.vanniktech.maven.publish.base")
// When scripts are applied the buildscript classes are not accessible directly therefore we save
// the class here to make it accessible.
ext.set("bndBundleTaskExtensionClass", BundleTaskExtension::class.java)
allprojects {
group = project.property("GROUP") as String
version = project.property("VERSION_NAME") as String
repositories {
mavenCentral()
google()
}
tasks.withType<DokkaTask>().configureEach {
dokkaSourceSets.configureEach {
reportUndocumented.set(false)
skipDeprecated.set(true)
jdkVersion.set(8)
perPackageOption {
matchingRegex.set("com\\.squareup.okio.*")
suppress.set(true)
}
perPackageOption {
matchingRegex.set("okio\\.internal.*")
suppress.set(true)
}
}
if (name == "dokkaHtml") {
outputDirectory.set(file("${rootDir}/docs/3.x/${project.name}"))
pluginsMapConfiguration.set(
mapOf(
"org.jetbrains.dokka.base.DokkaBase" to """
{
"customStyleSheets": [
"${rootDir.toString().replace('\\', '/')}/docs/css/dokka-logo.css"
],
"customAssets" : [
"${rootDir.toString().replace('\\', '/')}/docs/images/icon-square.png"
]
}
""".trimIndent()
)
)
}
}
plugins.withId("com.vanniktech.maven.publish.base") {
configure<PublishingExtension> {
repositories {
/**
* Want to push to an internal repository for testing? Set the following properties in
* `~/.gradle/gradle.properties`.
*
* internalMavenUrl=YOUR_INTERNAL_MAVEN_REPOSITORY_URL
* internalMavenUsername=YOUR_USERNAME
* internalMavenPassword=YOUR_PASSWORD
*/
val internalUrl = providers.gradleProperty("internalUrl")
if (internalUrl.isPresent) {
maven {
name = "internal"
setUrl(internalUrl)
credentials(PasswordCredentials::class)
}
}
}
}
val publishingExtension = extensions.getByType(PublishingExtension::class.java)
configure<MavenPublishBaseExtension> {
publishToMavenCentral(SonatypeHost.S01, automaticRelease = true)
signAllPublications()
pom {
description.set("A modern I/O library for Android, Java, and Kotlin Multiplatform.")
name.set(project.name)
url.set("https://github.com/square/okio/")
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
scm {
url.set("https://github.com/square/okio/")
connection.set("scm:git:git://github.com/square/okio.git")
developerConnection.set("scm:git:ssh://[email protected]/square/okio.git")
}
developers {
developer {
id.set("square")
name.set("Square, Inc.")
}
}
}
// Configure the kotlinMultiplatform artifact to depend on the JVM artifact in pom.xml only.
// This hack allows Maven users to continue using our original Okio artifact names (like
// com.squareup.okio:okio:3.x.y) even though we changed that artifact from JVM-only to Kotlin
// Multiplatform. Note that module.json doesn't need this hack.
val mavenPublications = publishingExtension.publications.withType<MavenPublication>()
mavenPublications.configureEach {
if (name != "jvm") return@configureEach
val jvmPublication = this
val kmpPublication = mavenPublications.getByName("kotlinMultiplatform")
kmpPublication.pom.withXml {
val root = asNode()
val dependencies = (root["dependencies"] as NodeList).firstOrNull() as Node?
?: root.appendNode("dependencies")
for (child in dependencies.children().toList()) {
dependencies.remove(child as Node)
}
dependencies.appendNode("dependency").apply {
appendNode("groupId", jvmPublication.groupId)
appendNode("artifactId", jvmPublication.artifactId)
appendNode("version", jvmPublication.version)
appendNode("scope", "compile")
}
}
}
}
}
}
subprojects {
apply(plugin = "com.diffplug.spotless")
configure<SpotlessExtension> {
kotlin {
target("**/*.kt")
ktlint(libs.versions.ktlint.get())
}
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
@Suppress("SuspiciousCollectionReassignment")
freeCompilerArgs += "-Xjvm-default=all"
}
}
tasks.withType<JavaCompile> {
options.encoding = StandardCharsets.UTF_8.toString()
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
}
val testJavaVersion = System.getProperty("test.java.version", "19").toInt()
tasks.withType<Test> {
val javaToolchains = project.extensions.getByType<JavaToolchainService>()
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(testJavaVersion))
})
testLogging {
events(STARTED, PASSED, SKIPPED, FAILED)
exceptionFormat = TestExceptionFormat.FULL
showStandardStreams = false
}
if (loomEnabled) {
jvmArgs = jvmArgs!! + listOf(
"-Djdk.tracePinnedThread=full",
"--enable-preview",
"-DloomEnabled=true"
)
}
}
tasks.withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
normalization {
runtimeClasspath {
metaInf {
ignoreAttribute("Bnd-LastModified")
}
}
}
}
/**
* Select a NodeJS version with WASI and WASM GC.
* https://github.com/Kotlin/kotlin-wasm-examples/blob/main/wasi-example/build.gradle.kts
*/
plugins.withType<NodeJsRootPlugin> {
extensions.getByType<NodeJsRootExtension>().apply {
if (DefaultNativePlatform.getCurrentOperatingSystem().isWindows) {
// We're waiting for a Windows build of NodeJS that can do WASM GC + WASI.
nodeVersion = "21.4.0"
} else {
nodeVersion = "21.0.0-v8-canary202309143a48826a08"
nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
}
}
// Suppress an error because yarn doesn't like our Node version string.
// warning You are using Node "21.0.0-v8-canary202309143a48826a08" which is not supported and
// may encounter bugs or unexpected behavior.
// error [email protected]: The engine "node" is incompatible with this module.
tasks.withType<KotlinNpmInstallTask>().all {
args += "--ignore-engines"
}
}
/**
* Set the `OKIO_ROOT` environment variable for tests to access it.
* https://publicobject.com/2023/04/16/read-a-project-file-in-a-kotlin-multiplatform-test/
*/
allprojects {
tasks.withType<KotlinJvmTest>().configureEach {
environment("OKIO_ROOT", rootDir)
}
tasks.withType<KotlinNativeTest>().configureEach {
environment("SIMCTL_CHILD_OKIO_ROOT", rootDir)
environment("OKIO_ROOT", rootDir)
}
tasks.withType<KotlinJsTest>().configureEach {
environment("OKIO_ROOT", rootDir.toString())
}
}