diff --git a/build.gradle.kts b/build.gradle.kts index ed3e56d..006e1bc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } group = "scientifik" -version = "0.2.0" +version = "0.2.1" repositories { gradlePluginPortal() diff --git a/src/main/kotlin/scientifik/ScientifikExtension.kt b/src/main/kotlin/scientifik/ScientifikExtension.kt index 8f079af..975618e 100644 --- a/src/main/kotlin/scientifik/ScientifikExtension.kt +++ b/src/main/kotlin/scientifik/ScientifikExtension.kt @@ -1,15 +1,49 @@ package scientifik +import Scientifik import org.gradle.api.Project import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.findByType +import org.gradle.kotlin.dsl.get +import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension + +private fun Project.applyMPPDependency(vararg pairs: Pair) { + val map = mapOf(*pairs) + extensions.findByType()?.apply { + pairs.forEach{(target,depString)-> + sourceSets[target].apply { + dependencies { + api(depString) + } + } + + } + } + extensions.findByType()?.apply { + sourceSets["main"].apply { + dependencies { + api(map["jvmMain"] ?: error("jvmMain dependency not found")) + } + } + } + + extensions.findByType()?.apply { + sourceSets["main"].apply { + dependencies { + api(map["jsMain"] ?: error("jsMain dependency not found")) + } + } + } +} open class ScientifikExtension { fun Project.withDokka() { apply(plugin = "org.jetbrains.dokka") subprojects { - this.scientifik.apply{ + scientifik.apply { withDokka() } } @@ -17,27 +51,31 @@ open class ScientifikExtension { fun Project.withSerialization() { apply(plugin = "kotlinx-serialization") - serialization = true + applyMPPDependency( + "commonMain" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:${Scientifik.serializationVersion}", + "jvmMain" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}", + "jsMain" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:${Scientifik.serializationVersion}" + ) //recursively apply to all subprojecs - subprojects{ - this.scientifik.apply{ + subprojects { + scientifik.apply { withSerialization() } } } - var serialization = false - private set - - fun Project.withIO(){ - io = true - subprojects{ - withIO() + fun Project.withIO() { + applyMPPDependency( + "commonMain" to "org.jetbrains.kotlinx:kotlinx-io:${Scientifik.ioVersion}", + "jvmMain" to "org.jetbrains.kotlinx:kotlinx-io-jvm:${Scientifik.ioVersion}", + "jsMain" to "org.jetbrains.kotlinx:kotlinx-io-js:${Scientifik.ioVersion}" + ) + subprojects { + scientifik.apply { + withIO() + } } } - - var io = false - private set } internal val Project.scientifik: ScientifikExtension diff --git a/src/main/kotlin/scientifik/ScientifikJSPlugin.kt b/src/main/kotlin/scientifik/ScientifikJSPlugin.kt index 9057683..f746979 100644 --- a/src/main/kotlin/scientifik/ScientifikJSPlugin.kt +++ b/src/main/kotlin/scientifik/ScientifikJSPlugin.kt @@ -1,6 +1,5 @@ package scientifik -import Scientifik import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.tasks.Copy @@ -30,14 +29,6 @@ open class ScientifikJSPlugin : Plugin { dependencies { api(kotlin("stdlib-js")) - afterEvaluate { - if (extension.serialization) { - implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}") - } - if (extension.io) { - api("org.jetbrains.kotlinx:kotlinx-io-js:${Scientifik.ioVersion}") - } - } } } } diff --git a/src/main/kotlin/scientifik/ScientifikJVMPlugin.kt b/src/main/kotlin/scientifik/ScientifikJVMPlugin.kt index 861f2c9..851061e 100644 --- a/src/main/kotlin/scientifik/ScientifikJVMPlugin.kt +++ b/src/main/kotlin/scientifik/ScientifikJVMPlugin.kt @@ -1,6 +1,5 @@ package scientifik -import Scientifik import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.plugins.JavaBasePlugin @@ -31,17 +30,8 @@ open class ScientifikJVMPlugin : Plugin { configure { val sourceSet = sourceSets["main"].apply { languageSettings.applySettings() - dependencies { api(kotlin("stdlib-jdk8")) - afterEvaluate { - if (extension.serialization) { - implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}") - } - if (extension.io) { - api("org.jetbrains.kotlinx:kotlinx-io-jvm:${Scientifik.ioVersion}") - } - } } } diff --git a/src/main/kotlin/scientifik/ScientifikMPPlugin.kt b/src/main/kotlin/scientifik/ScientifikMPPlugin.kt index 8d03da9..ffacd6e 100644 --- a/src/main/kotlin/scientifik/ScientifikMPPlugin.kt +++ b/src/main/kotlin/scientifik/ScientifikMPPlugin.kt @@ -1,6 +1,5 @@ package scientifik -import Scientifik import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.plugins.JavaBasePlugin @@ -42,14 +41,6 @@ open class ScientifikMPPlugin : Plugin { val commonMain by getting { dependencies { api(kotlin("stdlib")) - project.afterEvaluate { - if (extension.serialization) { - implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:${Scientifik.serializationVersion}") - } - if (extension.io) { - api("org.jetbrains.kotlinx:kotlinx-io:${Scientifik.ioVersion}") - } - } } } val commonTest by getting { @@ -61,15 +52,6 @@ open class ScientifikMPPlugin : Plugin { val jvmMain by getting { dependencies { api(kotlin("stdlib-jdk8")) - project.afterEvaluate { - if (extension.serialization) { - implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}") - } - - if (extension.io) { - api("org.jetbrains.kotlinx:kotlinx-io-jvm:${Scientifik.ioVersion}") - } - } } } val jvmTest by getting { @@ -81,15 +63,6 @@ open class ScientifikMPPlugin : Plugin { val jsMain by getting { dependencies { api(kotlin("stdlib-js")) - project.afterEvaluate { - if (extension.serialization) { - implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:${Scientifik.serializationVersion}") - } - - if (extension.io) { - api("org.jetbrains.kotlinx:kotlinx-io-js:${Scientifik.ioVersion}") - } - } } } val jsTest by getting {