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