diff --git a/build.gradle.kts b/build.gradle.kts index 7ba40fd..86d87b9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,5 @@ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask import org.jetbrains.dokka.gradle.DokkaTask -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile val ossrhUsername: String? by ext val ossrhPassword: String? by ext @@ -10,7 +9,7 @@ description = "A Result monad for modelling success or failure operations." plugins { `maven-publish` signing - kotlin("jvm") version "1.3.72" + kotlin("multiplatform") version "1.3.72" id("org.jetbrains.dokka") version "0.10.1" id("com.github.ben-manes.versions") version "0.28.0" id("net.researchgate.release") version "2.8.1" @@ -18,52 +17,6 @@ plugins { id("org.jetbrains.kotlin.plugin.allopen") version "1.3.72" } -allprojects { - repositories { - mavenCentral() - jcenter() - maven("https://dl.bintray.com/kotlin/kotlinx") - } - - tasks.withType { - kotlinOptions { - jvmTarget = "1.8" - freeCompilerArgs = listOf("-Xuse-experimental=kotlin.contracts.ExperimentalContracts") - } - } -} - -allOpen { - annotation("org.openjdk.jmh.annotations.State") - annotation("org.openjdk.jmh.annotations.BenchmarkMode") -} - -sourceSets.create("benchmark") { - java { - srcDir("src/benchmarks/kotlin") - } -} - -val benchmarkImplementation by configurations - -benchmark { - targets { - register("benchmark") - } -} - -dependencies { - implementation(kotlin("stdlib")) - testImplementation("junit:junit:4.13") - testImplementation(kotlin("test-common")) - testImplementation(kotlin("test-annotations-common")) - testImplementation(kotlin("test-junit")) - testImplementation(kotlin("test")) - - benchmarkImplementation(sourceSets.main.get().output + sourceSets.main.get().runtimeClasspath) - benchmarkImplementation("org.jetbrains.kotlinx:kotlinx.benchmark.runtime-jvm:0.2.0-dev-8") -} - tasks.withType { rejectVersionIf { listOf("alpha", "beta", "rc", "cr", "m", "eap", "pr").any { @@ -85,11 +38,82 @@ val javadocJar by tasks.registering(Jar::class) { from(dokka.get().outputDirectory) } -val sourcesJar by tasks.registering(Jar::class) { - group = LifecycleBasePlugin.BUILD_GROUP - description = "Assembles a jar archive containing the main classes with sources." - archiveClassifier.set("sources") - from(sourceSets["main"].allSource) +allprojects { + repositories { + mavenCentral() + jcenter() + maven("https://dl.bintray.com/kotlin/kotlinx") + } +} + +allOpen { + annotation("org.openjdk.jmh.annotations.State") + annotation("org.openjdk.jmh.annotations.BenchmarkMode") +} + +sourceSets.create("benchmark") + +benchmark { + targets { + register("jvmBenchmark") + } +} + +kotlin { + jvm { + withJava() + + mavenPublication { + artifact(javadocJar.get()) + } + + compilations.all { + kotlinOptions { + jvmTarget = "1.8" + } + } + } + + sourceSets { + all { + languageSettings.apply { + useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") + } + } + + val commonMain by getting { + dependencies { + implementation(kotlin("stdlib-common")) + } + } + + val commonTest by getting { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + } + } + + val jvmMain by getting { + dependencies { + implementation(kotlin("stdlib-jdk8")) + } + } + + val jvmTest by getting { + dependencies { + implementation(kotlin("test-junit")) + implementation(kotlin("test")) + } + } + + val jvmBenchmark by getting { + dependsOn(jvmMain) + dependencies { + implementation("org.jetbrains.kotlinx:kotlinx.benchmark.runtime-jvm:0.2.0-dev-8") + } + } + } } publishing { @@ -108,64 +132,58 @@ publishing { } } - publications { - register("mavenJava", MavenPublication::class) { - from(components["java"]) - artifact(javadocJar.get()) - artifact(sourcesJar.get()) + publications.withType { + pom { + name.set(project.name) + description.set(project.description) + url.set("https://github.com/michaelbull/kotlin-result") + inceptionYear.set("2017") - pom { - name.set(project.name) - description.set(project.description) + licenses { + license { + name.set("ISC License") + url.set("https://opensource.org/licenses/isc-license.txt") + } + } + + developers { + developer { + name.set("Michael Bull") + url.set("https://www.michael-bull.com") + } + } + + contributors { + contributor { + name.set("Kevin Herron") + url.set("https://github.com/kevinherron") + } + + contributor { + name.set("Markus Padourek") + url.set("https://github.com/Globegitter") + } + + contributor { + name.set("Tristan Hamilton") + url.set("https://github.com/Munzey") + } + } + + scm { + connection.set("scm:git:https://github.com/michaelbull/kotlin-result") + developerConnection.set("scm:git:git@github.com:michaelbull/kotlin-result.git") url.set("https://github.com/michaelbull/kotlin-result") - inceptionYear.set("2017") + } - licenses { - license { - name.set("ISC License") - url.set("https://opensource.org/licenses/isc-license.txt") - } - } + issueManagement { + system.set("GitHub") + url.set("https://github.com/michaelbull/kotlin-result/issues") + } - developers { - developer { - name.set("Michael Bull") - url.set("https://www.michael-bull.com") - } - } - - contributors { - contributor { - name.set("Kevin Herron") - url.set("https://github.com/kevinherron") - } - - contributor { - name.set("Markus Padourek") - url.set("https://github.com/Globegitter") - } - - contributor { - name.set("Tristan Hamilton") - url.set("https://github.com/Munzey") - } - } - - scm { - connection.set("scm:git:https://github.com/michaelbull/kotlin-result") - developerConnection.set("scm:git:git@github.com:michaelbull/kotlin-result.git") - url.set("https://github.com/michaelbull/kotlin-result") - } - - issueManagement { - system.set("GitHub") - url.set("https://github.com/michaelbull/kotlin-result/issues") - } - - ciManagement { - system.set("GitHub") - url.set("https://github.com/michaelbull/kotlin-result/actions?query=workflow%3Aci") - } + ciManagement { + system.set("GitHub") + url.set("https://github.com/michaelbull/kotlin-result/actions?query=workflow%3Aci") } } } diff --git a/example/build.gradle.kts b/example/build.gradle.kts index 13cab51..2bf8eb4 100644 --- a/example/build.gradle.kts +++ b/example/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + plugins { application kotlin("jvm") @@ -22,3 +24,9 @@ dependencies { implementation("io.ktor:ktor-server-netty:$ktorVersion") implementation("io.ktor:ktor-gson:$ktorVersion") } + +tasks.withType(KotlinCompile::class.java).all { + kotlinOptions { + jvmTarget = "1.8" + } +} diff --git a/src/main/kotlin/com/github/michaelbull/result/And.kt b/src/commonMain/kotlin/com/github/michaelbull/result/And.kt similarity index 100% rename from src/main/kotlin/com/github/michaelbull/result/And.kt rename to src/commonMain/kotlin/com/github/michaelbull/result/And.kt diff --git a/src/main/kotlin/com/github/michaelbull/result/Binding.kt b/src/commonMain/kotlin/com/github/michaelbull/result/Binding.kt similarity index 93% rename from src/main/kotlin/com/github/michaelbull/result/Binding.kt rename to src/commonMain/kotlin/com/github/michaelbull/result/Binding.kt index fcf5b6d..b586634 100644 --- a/src/main/kotlin/com/github/michaelbull/result/Binding.kt +++ b/src/commonMain/kotlin/com/github/michaelbull/result/Binding.kt @@ -38,11 +38,7 @@ inline fun binding(crossinline block: ResultBinding.() -> V): Result { fun Result.bind(): V diff --git a/src/main/kotlin/com/github/michaelbull/result/Factory.kt b/src/commonMain/kotlin/com/github/michaelbull/result/Factory.kt similarity index 100% rename from src/main/kotlin/com/github/michaelbull/result/Factory.kt rename to src/commonMain/kotlin/com/github/michaelbull/result/Factory.kt diff --git a/src/main/kotlin/com/github/michaelbull/result/Get.kt b/src/commonMain/kotlin/com/github/michaelbull/result/Get.kt similarity index 100% rename from src/main/kotlin/com/github/michaelbull/result/Get.kt rename to src/commonMain/kotlin/com/github/michaelbull/result/Get.kt diff --git a/src/main/kotlin/com/github/michaelbull/result/Iterable.kt b/src/commonMain/kotlin/com/github/michaelbull/result/Iterable.kt similarity index 100% rename from src/main/kotlin/com/github/michaelbull/result/Iterable.kt rename to src/commonMain/kotlin/com/github/michaelbull/result/Iterable.kt diff --git a/src/main/kotlin/com/github/michaelbull/result/Map.kt b/src/commonMain/kotlin/com/github/michaelbull/result/Map.kt similarity index 100% rename from src/main/kotlin/com/github/michaelbull/result/Map.kt rename to src/commonMain/kotlin/com/github/michaelbull/result/Map.kt diff --git a/src/main/kotlin/com/github/michaelbull/result/On.kt b/src/commonMain/kotlin/com/github/michaelbull/result/On.kt similarity index 100% rename from src/main/kotlin/com/github/michaelbull/result/On.kt rename to src/commonMain/kotlin/com/github/michaelbull/result/On.kt diff --git a/src/main/kotlin/com/github/michaelbull/result/Or.kt b/src/commonMain/kotlin/com/github/michaelbull/result/Or.kt similarity index 100% rename from src/main/kotlin/com/github/michaelbull/result/Or.kt rename to src/commonMain/kotlin/com/github/michaelbull/result/Or.kt diff --git a/src/main/kotlin/com/github/michaelbull/result/Result.kt b/src/commonMain/kotlin/com/github/michaelbull/result/Result.kt similarity index 100% rename from src/main/kotlin/com/github/michaelbull/result/Result.kt rename to src/commonMain/kotlin/com/github/michaelbull/result/Result.kt diff --git a/src/main/kotlin/com/github/michaelbull/result/ResultIterator.kt b/src/commonMain/kotlin/com/github/michaelbull/result/ResultIterator.kt similarity index 100% rename from src/main/kotlin/com/github/michaelbull/result/ResultIterator.kt rename to src/commonMain/kotlin/com/github/michaelbull/result/ResultIterator.kt diff --git a/src/main/kotlin/com/github/michaelbull/result/Unwrap.kt b/src/commonMain/kotlin/com/github/michaelbull/result/Unwrap.kt similarity index 100% rename from src/main/kotlin/com/github/michaelbull/result/Unwrap.kt rename to src/commonMain/kotlin/com/github/michaelbull/result/Unwrap.kt diff --git a/src/main/kotlin/com/github/michaelbull/result/Zip.kt b/src/commonMain/kotlin/com/github/michaelbull/result/Zip.kt similarity index 100% rename from src/main/kotlin/com/github/michaelbull/result/Zip.kt rename to src/commonMain/kotlin/com/github/michaelbull/result/Zip.kt diff --git a/src/test/kotlin/com/github/michaelbull/result/AndTest.kt b/src/commonTest/kotlin/com/github/michaelbull/result/AndTest.kt similarity index 100% rename from src/test/kotlin/com/github/michaelbull/result/AndTest.kt rename to src/commonTest/kotlin/com/github/michaelbull/result/AndTest.kt diff --git a/src/test/kotlin/com/github/michaelbull/result/BindingTest.kt b/src/commonTest/kotlin/com/github/michaelbull/result/BindingTest.kt similarity index 100% rename from src/test/kotlin/com/github/michaelbull/result/BindingTest.kt rename to src/commonTest/kotlin/com/github/michaelbull/result/BindingTest.kt diff --git a/src/test/kotlin/com/github/michaelbull/result/FactoryTest.kt b/src/commonTest/kotlin/com/github/michaelbull/result/FactoryTest.kt similarity index 100% rename from src/test/kotlin/com/github/michaelbull/result/FactoryTest.kt rename to src/commonTest/kotlin/com/github/michaelbull/result/FactoryTest.kt diff --git a/src/test/kotlin/com/github/michaelbull/result/GetTest.kt b/src/commonTest/kotlin/com/github/michaelbull/result/GetTest.kt similarity index 100% rename from src/test/kotlin/com/github/michaelbull/result/GetTest.kt rename to src/commonTest/kotlin/com/github/michaelbull/result/GetTest.kt diff --git a/src/test/kotlin/com/github/michaelbull/result/IterableTest.kt b/src/commonTest/kotlin/com/github/michaelbull/result/IterableTest.kt similarity index 100% rename from src/test/kotlin/com/github/michaelbull/result/IterableTest.kt rename to src/commonTest/kotlin/com/github/michaelbull/result/IterableTest.kt diff --git a/src/test/kotlin/com/github/michaelbull/result/MapTest.kt b/src/commonTest/kotlin/com/github/michaelbull/result/MapTest.kt similarity index 100% rename from src/test/kotlin/com/github/michaelbull/result/MapTest.kt rename to src/commonTest/kotlin/com/github/michaelbull/result/MapTest.kt diff --git a/src/test/kotlin/com/github/michaelbull/result/OnTest.kt b/src/commonTest/kotlin/com/github/michaelbull/result/OnTest.kt similarity index 100% rename from src/test/kotlin/com/github/michaelbull/result/OnTest.kt rename to src/commonTest/kotlin/com/github/michaelbull/result/OnTest.kt diff --git a/src/test/kotlin/com/github/michaelbull/result/OrTest.kt b/src/commonTest/kotlin/com/github/michaelbull/result/OrTest.kt similarity index 100% rename from src/test/kotlin/com/github/michaelbull/result/OrTest.kt rename to src/commonTest/kotlin/com/github/michaelbull/result/OrTest.kt diff --git a/src/test/kotlin/com/github/michaelbull/result/ResultIteratorTest.kt b/src/commonTest/kotlin/com/github/michaelbull/result/ResultIteratorTest.kt similarity index 100% rename from src/test/kotlin/com/github/michaelbull/result/ResultIteratorTest.kt rename to src/commonTest/kotlin/com/github/michaelbull/result/ResultIteratorTest.kt diff --git a/src/test/kotlin/com/github/michaelbull/result/UnwrapTest.kt b/src/commonTest/kotlin/com/github/michaelbull/result/UnwrapTest.kt similarity index 100% rename from src/test/kotlin/com/github/michaelbull/result/UnwrapTest.kt rename to src/commonTest/kotlin/com/github/michaelbull/result/UnwrapTest.kt diff --git a/src/benchmark/kotlin/com/github/michaelbull/result/BindingBenchmark.kt b/src/jvmBenchmark/kotlin/com/github/michaelbull/result/BindingBenchmark.kt similarity index 100% rename from src/benchmark/kotlin/com/github/michaelbull/result/BindingBenchmark.kt rename to src/jvmBenchmark/kotlin/com/github/michaelbull/result/BindingBenchmark.kt diff --git a/src/jvmMain/kotlin/com/github/michaelbull/result/BindException.kt b/src/jvmMain/kotlin/com/github/michaelbull/result/BindException.kt new file mode 100644 index 0000000..3ad6678 --- /dev/null +++ b/src/jvmMain/kotlin/com/github/michaelbull/result/BindException.kt @@ -0,0 +1,7 @@ +package com.github.michaelbull.result + +internal actual object BindException : Exception() { + override fun fillInStackTrace(): Throwable { + return this + } +}