From 91d0bd9d2e97595c8fcd0bba69949e5d2b0553be Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 20 Jul 2019 20:39:26 +0300 Subject: [PATCH] Conditional configuration for serialization --- build.gradle.kts | 1 + .../kotlin/scientifik/ScientifikExtension.kt | 3 +- .../kotlin/scientifik/ScientifikMPPlugin.kt | 45 +++++++++++++------ .../scientifik/ScientifikPublishPlugin.kt | 8 ++-- 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index e04c37e..f54b51c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,6 +20,7 @@ val kotlinVersion = "1.3.50-eap-5" // Add plugins used in buildSrc as dependencies, also we should specify version only here dependencies { implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") + implementation("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion") implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.9.7") implementation("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4") implementation("org.jetbrains.dokka:dokka-gradle-plugin:0.9.18") diff --git a/src/main/kotlin/scientifik/ScientifikExtension.kt b/src/main/kotlin/scientifik/ScientifikExtension.kt index 7c595e0..4f1cfb8 100644 --- a/src/main/kotlin/scientifik/ScientifikExtension.kt +++ b/src/main/kotlin/scientifik/ScientifikExtension.kt @@ -9,7 +9,8 @@ open class ScientifikExtension { var vcs: String? = null var bintrayRepo: String? = null var kdoc: Boolean = true - var enableNative = false + var native = false + var serialization = false } internal val Project.scientifik: ScientifikExtension diff --git a/src/main/kotlin/scientifik/ScientifikMPPlugin.kt b/src/main/kotlin/scientifik/ScientifikMPPlugin.kt index cf6722d..6eaa6d2 100644 --- a/src/main/kotlin/scientifik/ScientifikMPPlugin.kt +++ b/src/main/kotlin/scientifik/ScientifikMPPlugin.kt @@ -1,5 +1,6 @@ package scientifik +import Scientifik import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.* @@ -7,10 +8,20 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension open class ScientifikMPPlugin : Plugin { override fun apply(project: Project) { - project.plugins.apply("org.jetbrains.kotlin.multiplatform") - val extension = project.scientifik + project.plugins.apply("org.jetbrains.kotlin.multiplatform") + project.plugins.apply("kotlinx-serialization") + + project.repositories { + mavenCentral() + jcenter() + maven("https://dl.bintray.com/kotlin/kotlin-eap") + maven("https://kotlin.bintray.com/kotlinx") + maven("https://dl.bintray.com/mipt-npm/dev") + maven("https://dl.bintray.com/mipt-npm/scientifik") + } + project.configure { jvm { compilations.all { @@ -30,7 +41,7 @@ open class ScientifikMPPlugin : Plugin { } } - if(extension.enableNative){ + if (extension.native) { linuxX64() mingwX64() } @@ -39,6 +50,11 @@ open class ScientifikMPPlugin : Plugin { val commonMain by getting { dependencies { api(kotlin("stdlib")) + project.afterEvaluate { + if (extension.serialization) { + api("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}") + } + } } } val commonTest by getting { @@ -69,24 +85,25 @@ open class ScientifikMPPlugin : Plugin { } } - if(extension.enableNative){ - val native by creating { - dependsOn(commonMain) - } - mingwX64().compilations["main"].defaultSourceSet { - dependsOn(native) - } - linuxX64().compilations["main"].defaultSourceSet { - dependsOn(native) + project.afterEvaluate { + if (extension.native) { + val native by creating { + dependsOn(commonMain) + } + mingwX64().compilations["main"].defaultSourceSet { + dependsOn(native) + } + linuxX64().compilations["main"].defaultSourceSet { + dependsOn(native) + } } } } targets.all { sourceSets.all { - languageSettings.apply{ + languageSettings.apply { progressiveMode = true - this. enableLanguageFeature("InlineClasses") useExperimentalAnnotation("ExperimentalUnsignedType") } diff --git a/src/main/kotlin/scientifik/ScientifikPublishPlugin.kt b/src/main/kotlin/scientifik/ScientifikPublishPlugin.kt index db7d6df..4d954f4 100644 --- a/src/main/kotlin/scientifik/ScientifikPublishPlugin.kt +++ b/src/main/kotlin/scientifik/ScientifikPublishPlugin.kt @@ -45,12 +45,12 @@ open class ScientifikPublishPlugin : Plugin { project.plugins.apply("maven-publish") val extension = project.scientifik - if (extension.kdoc) { - project.plugins.apply("org.jetbrains.dokka") - } - project.afterEvaluate { + if (extension.kdoc) { + project.plugins.apply("org.jetbrains.dokka") + } + val bintrayRepo = project.bintrayRepo val vcs = project.vcs