1 import aQute.bnd.gradle.BundleTaskExtension
2 import com.diffplug.gradle.spotless.SpotlessExtension
3 import com.vanniktech.maven.publish.MavenPublishBaseExtension
4 import com.vanniktech.maven.publish.SonatypeHost
5 import groovy.util.Node
6 import groovy.util.NodeList
7 import java.nio.charset.StandardCharsets
8 import org.gradle.api.tasks.testing.logging.TestExceptionFormat
9 import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
10 import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
11 import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED
12 import org.gradle.api.tasks.testing.logging.TestLogEvent.STARTED
13 import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
14 import org.jetbrains.dokka.gradle.DokkaTask
15 import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
16 import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
17 import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
18 import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
19 import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
20 import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
21 import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
22
<lambda>null23 plugins {
24 id("build-support").apply(false)
25 }
26
<lambda>null27 buildscript {
28 dependencies {
29 classpath(libs.android.gradle.plugin)
30 classpath(libs.burst.gradle.plugin)
31 classpath(libs.dokka)
32 classpath(libs.jmh.gradle.plugin)
33 classpath(libs.binaryCompatibilityValidator)
34 classpath(libs.spotless)
35 classpath(libs.bnd)
36 classpath(libs.vanniktech.publish.plugin)
37 }
38
39 repositories {
40 mavenCentral()
41 gradlePluginPortal()
42 google()
43 }
44 }
45
46 apply(plugin = "com.vanniktech.maven.publish.base")
47
48 // When scripts are applied the buildscript classes are not accessible directly therefore we save
49 // the class here to make it accessible.
50 ext.set("bndBundleTaskExtensionClass", BundleTaskExtension::class.java)
51
<lambda>null52 allprojects {
53 group = project.property("GROUP") as String
54 version = project.property("VERSION_NAME") as String
55
56 repositories {
57 mavenCentral()
58 google()
59 }
60
61 tasks.withType<DokkaTask>().configureEach {
62 dokkaSourceSets.configureEach {
63 reportUndocumented.set(false)
64 skipDeprecated.set(true)
65 jdkVersion.set(8)
66 perPackageOption {
67 matchingRegex.set("com\\.squareup.okio.*")
68 suppress.set(true)
69 }
70 perPackageOption {
71 matchingRegex.set("okio\\.internal.*")
72 suppress.set(true)
73 }
74 }
75
76 if (name == "dokkaHtml") {
77 outputDirectory.set(file("${rootDir}/docs/3.x/${project.name}"))
78 pluginsMapConfiguration.set(
79 mapOf(
80 "org.jetbrains.dokka.base.DokkaBase" to """
81 {
82 "customStyleSheets": [
83 "${rootDir.toString().replace('\\', '/')}/docs/css/dokka-logo.css"
84 ],
85 "customAssets" : [
86 "${rootDir.toString().replace('\\', '/')}/docs/images/icon-square.png"
87 ]
88 }
89 """.trimIndent()
90 )
91 )
92 }
93 }
94
95 plugins.withId("com.vanniktech.maven.publish.base") {
96 configure<PublishingExtension> {
97 repositories {
98 /**
99 * Want to push to an internal repository for testing? Set the following properties in
100 * `~/.gradle/gradle.properties`.
101 *
102 * internalMavenUrl=YOUR_INTERNAL_MAVEN_REPOSITORY_URL
103 * internalMavenUsername=YOUR_USERNAME
104 * internalMavenPassword=YOUR_PASSWORD
105 */
106 val internalUrl = providers.gradleProperty("internalUrl")
107 if (internalUrl.isPresent) {
108 maven {
109 name = "internal"
110 setUrl(internalUrl)
111 credentials(PasswordCredentials::class)
112 }
113 }
114 }
115 }
116 val publishingExtension = extensions.getByType(PublishingExtension::class.java)
117 configure<MavenPublishBaseExtension> {
118 publishToMavenCentral(SonatypeHost.S01, automaticRelease = true)
119 signAllPublications()
120 pom {
121 description.set("A modern I/O library for Android, Java, and Kotlin Multiplatform.")
122 name.set(project.name)
123 url.set("https://github.com/square/okio/")
124 licenses {
125 license {
126 name.set("The Apache Software License, Version 2.0")
127 url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
128 distribution.set("repo")
129 }
130 }
131 scm {
132 url.set("https://github.com/square/okio/")
133 connection.set("scm:git:git://github.com/square/okio.git")
134 developerConnection.set("scm:git:ssh://git@github.com/square/okio.git")
135 }
136 developers {
137 developer {
138 id.set("square")
139 name.set("Square, Inc.")
140 }
141 }
142 }
143
144 // Configure the kotlinMultiplatform artifact to depend on the JVM artifact in pom.xml only.
145 // This hack allows Maven users to continue using our original Okio artifact names (like
146 // com.squareup.okio:okio:3.x.y) even though we changed that artifact from JVM-only to Kotlin
147 // Multiplatform. Note that module.json doesn't need this hack.
148 val mavenPublications = publishingExtension.publications.withType<MavenPublication>()
149 mavenPublications.configureEach {
150 if (name != "jvm") return@configureEach
151 val jvmPublication = this
152 val kmpPublication = mavenPublications.getByName("kotlinMultiplatform")
153 kmpPublication.pom.withXml {
154 val root = asNode()
155 val dependencies = (root["dependencies"] as NodeList).firstOrNull() as Node?
156 ?: root.appendNode("dependencies")
157 for (child in dependencies.children().toList()) {
158 dependencies.remove(child as Node)
159 }
160 dependencies.appendNode("dependency").apply {
161 appendNode("groupId", jvmPublication.groupId)
162 appendNode("artifactId", jvmPublication.artifactId)
163 appendNode("version", jvmPublication.version)
164 appendNode("scope", "compile")
165 }
166 }
167 }
168 }
169 }
170 }
171
<lambda>null172 subprojects {
173 apply(plugin = "com.diffplug.spotless")
174 configure<SpotlessExtension> {
175 kotlin {
176 target("**/*.kt")
177 ktlint(libs.versions.ktlint.get())
178 }
179 }
180
181 tasks.withType<KotlinCompile>().configureEach {
182 kotlinOptions {
183 jvmTarget = JavaVersion.VERSION_1_8.toString()
184 @Suppress("SuspiciousCollectionReassignment")
185 freeCompilerArgs += "-Xjvm-default=all"
186 }
187 }
188
189 tasks.withType<JavaCompile> {
190 options.encoding = StandardCharsets.UTF_8.toString()
191 sourceCompatibility = JavaVersion.VERSION_1_8.toString()
192 targetCompatibility = JavaVersion.VERSION_1_8.toString()
193 }
194
195 val testJavaVersion = System.getProperty("test.java.version", "19").toInt()
196 tasks.withType<Test> {
197 val javaToolchains = project.extensions.getByType<JavaToolchainService>()
198 javaLauncher.set(javaToolchains.launcherFor {
199 languageVersion.set(JavaLanguageVersion.of(testJavaVersion))
200 })
201
202 testLogging {
203 events(STARTED, PASSED, SKIPPED, FAILED)
204 exceptionFormat = TestExceptionFormat.FULL
205 showStandardStreams = false
206 }
207
208 if (loomEnabled) {
209 jvmArgs = jvmArgs!! + listOf(
210 "-Djdk.tracePinnedThread=full",
211 "--enable-preview",
212 "-DloomEnabled=true"
213 )
214 }
215 }
216
217 tasks.withType<AbstractArchiveTask>().configureEach {
218 isPreserveFileTimestamps = false
219 isReproducibleFileOrder = true
220 }
221
222 normalization {
223 runtimeClasspath {
224 metaInf {
225 ignoreAttribute("Bnd-LastModified")
226 }
227 }
228 }
229 }
230
231 /**
232 * Select a NodeJS version with WASI and WASM GC.
233 * https://github.com/Kotlin/kotlin-wasm-examples/blob/main/wasi-example/build.gradle.kts
234 */
<lambda>null235 plugins.withType<NodeJsRootPlugin> {
236 extensions.getByType<NodeJsRootExtension>().apply {
237 if (DefaultNativePlatform.getCurrentOperatingSystem().isWindows) {
238 // We're waiting for a Windows build of NodeJS that can do WASM GC + WASI.
239 nodeVersion = "21.4.0"
240 } else {
241 nodeVersion = "21.0.0-v8-canary202309143a48826a08"
242 nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
243 }
244 }
245 // Suppress an error because yarn doesn't like our Node version string.
246 // warning You are using Node "21.0.0-v8-canary202309143a48826a08" which is not supported and
247 // may encounter bugs or unexpected behavior.
248 // error typescript@5.0.4: The engine "node" is incompatible with this module.
249 tasks.withType<KotlinNpmInstallTask>().all {
250 args += "--ignore-engines"
251 }
252 }
253
254 /**
255 * Set the `OKIO_ROOT` environment variable for tests to access it.
256 * https://publicobject.com/2023/04/16/read-a-project-file-in-a-kotlin-multiplatform-test/
257 */
<lambda>null258 allprojects {
259 tasks.withType<KotlinJvmTest>().configureEach {
260 environment("OKIO_ROOT", rootDir)
261 }
262
263 tasks.withType<KotlinNativeTest>().configureEach {
264 environment("SIMCTL_CHILD_OKIO_ROOT", rootDir)
265 environment("OKIO_ROOT", rootDir)
266 }
267
268 tasks.withType<KotlinJsTest>().configureEach {
269 environment("OKIO_ROOT", rootDir.toString())
270 }
271 }
272