aboutsummaryrefslogtreecommitdiff
path: root/okio/build.gradle.kts
diff options
context:
space:
mode:
Diffstat (limited to 'okio/build.gradle.kts')
-rw-r--r--okio/build.gradle.kts197
1 files changed, 197 insertions, 0 deletions
diff --git a/okio/build.gradle.kts b/okio/build.gradle.kts
new file mode 100644
index 00000000..cac4a345
--- /dev/null
+++ b/okio/build.gradle.kts
@@ -0,0 +1,197 @@
+import aQute.bnd.gradle.BundleTaskConvention
+import com.vanniktech.maven.publish.JavadocJar.Dokka
+import com.vanniktech.maven.publish.KotlinMultiplatform
+import com.vanniktech.maven.publish.MavenPublishBaseExtension
+import kotlinx.validation.ApiValidationExtension
+import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithTests
+import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
+import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable
+
+plugins {
+ kotlin("multiplatform")
+ id("org.jetbrains.dokka")
+ id("com.vanniktech.maven.publish.base")
+ id("build-support")
+ id("binary-compatibility-validator")
+}
+
+/*
+ * Here's the main hierarchy of variants. Any `expect` functions in one level of the tree are
+ * `actual` functions in a (potentially indirect) child node.
+ *
+ * ```
+ * common
+ * |-- js
+ * |-- jvm
+ * |-- native
+ * | |-- mingw
+ * | | '-- mingwX64
+ * | '-- unix
+ * | |-- apple
+ * | | |-- iosArm64
+ * | | |-- iosX64
+ * | | |-- macosX64
+ * | | |-- tvosArm64
+ * | | |-- tvosX64
+ * | | |-- watchosArm32
+ * | | |-- watchosArm64
+ * | '-- linux
+ * | |-- linuxX64
+ * | '-- linuxArm64
+ * '-- wasm
+ * '-- wasmJs
+ * '-- wasmWasi
+ * ```
+ *
+ * The `nonJvm` source set excludes that platform.
+ *
+ * The `hashFunctions` source set builds on all platforms. It ships as a main source set on non-JVM
+ * platforms and as a test source set on the JVM platform.
+ */
+kotlin {
+ configureOrCreateOkioPlatforms()
+
+ sourceSets {
+ all {
+ languageSettings.apply {
+ // Required for CPointer etc. since Kotlin 1.9.
+ optIn("kotlinx.cinterop.ExperimentalForeignApi")
+ }
+ }
+
+ val commonMain by getting
+ val commonTest by getting {
+ dependencies {
+ implementation(libs.kotlin.test)
+ implementation(projects.okioTestingSupport)
+ }
+ }
+
+ val hashFunctions by creating {
+ dependsOn(commonMain)
+ }
+
+ val nonAppleMain by creating {
+ dependsOn(hashFunctions)
+ }
+
+ val nonWasmTest by creating {
+ dependencies {
+ implementation(libs.kotlin.time)
+ implementation(projects.okioFakefilesystem)
+ }
+ }
+
+ val nonJvmMain by creating {
+ dependsOn(hashFunctions)
+ dependsOn(commonMain)
+ }
+
+ val nonJvmTest by creating {
+ dependsOn(commonTest)
+ }
+
+ val jvmMain by getting {
+ }
+ val jvmTest by getting {
+ kotlin.srcDir("src/jvmTest/hashFunctions")
+ dependsOn(nonWasmTest)
+ dependencies {
+ implementation(libs.test.junit)
+ implementation(libs.test.assertj)
+ implementation(libs.test.jimfs)
+ }
+ }
+
+ if (kmpJsEnabled) {
+ val jsMain by getting {
+ dependsOn(nonJvmMain)
+ dependsOn(nonAppleMain)
+ }
+ val jsTest by getting {
+ dependsOn(nonWasmTest)
+ dependsOn(nonJvmTest)
+ }
+ }
+
+ if (kmpNativeEnabled) {
+ createSourceSet("nativeMain", parent = nonJvmMain)
+ .also { nativeMain ->
+ createSourceSet("mingwMain", parent = nativeMain, children = mingwTargets).also { mingwMain ->
+ mingwMain.dependsOn(nonAppleMain)
+ }
+ createSourceSet("unixMain", parent = nativeMain)
+ .also { unixMain ->
+ createSourceSet("linuxMain", parent = unixMain, children = linuxTargets).also { linuxMain ->
+ linuxMain.dependsOn(nonAppleMain)
+ }
+ createSourceSet("appleMain", parent = unixMain, children = appleTargets)
+ }
+ }
+
+ createSourceSet("nativeTest", parent = commonTest, children = mingwTargets + linuxTargets)
+ .also { nativeTest ->
+ nativeTest.dependsOn(nonJvmTest)
+ nativeTest.dependsOn(nonWasmTest)
+ createSourceSet("appleTest", parent = nativeTest, children = appleTargets)
+ }
+ }
+
+ if (kmpWasmEnabled) {
+ createSourceSet("wasmMain", parent = commonMain, children = wasmTargets)
+ .also { wasmMain ->
+ wasmMain.dependsOn(nonJvmMain)
+ wasmMain.dependsOn(nonAppleMain)
+ }
+ createSourceSet("wasmTest", parent = commonTest, children = wasmTargets)
+ .also { wasmTest ->
+ wasmTest.dependsOn(nonJvmTest)
+ }
+ }
+ }
+
+ targets.withType<KotlinNativeTargetWithTests<*>> {
+ binaries {
+ // Configure a separate test where code runs in background
+ test("background", setOf(NativeBuildType.DEBUG)) {
+ freeCompilerArgs += "-trw"
+ }
+ }
+ testRuns {
+ val background by creating {
+ setExecutionSourceFrom(binaries.getByName("backgroundDebugTest") as TestExecutable)
+ }
+ }
+ }
+}
+
+tasks {
+ val jvmJar by getting(Jar::class) {
+ // BundleTaskConvention() crashes unless there's a 'main' source set.
+ sourceSets.create(SourceSet.MAIN_SOURCE_SET_NAME)
+ val bndConvention = BundleTaskConvention(this)
+ bndConvention.setBnd(
+ """
+ Export-Package: okio
+ Automatic-Module-Name: okio
+ Bundle-SymbolicName: com.squareup.okio
+ """,
+ )
+ // Call the convention when the task has finished to modify the jar to contain OSGi metadata.
+ doLast {
+ bndConvention.buildBundle()
+ }
+ }
+}
+
+configure<MavenPublishBaseExtension> {
+ configure(
+ KotlinMultiplatform(javadocJar = Dokka("dokkaGfm")),
+ )
+}
+
+plugins.withId("binary-compatibility-validator") {
+ configure<ApiValidationExtension> {
+ ignoredProjects += "jmh"
+ }
+}