Conditional configuration for serialization

This commit is contained in:
Alexander Nozik 2019-07-20 20:39:26 +03:00
parent ab106cab82
commit 91d0bd9d2e
4 changed files with 38 additions and 19 deletions

View File

@ -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 // Add plugins used in buildSrc as dependencies, also we should specify version only here
dependencies { dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") 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("org.jfrog.buildinfo:build-info-extractor-gradle:4.9.7")
implementation("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4") implementation("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:0.9.18") implementation("org.jetbrains.dokka:dokka-gradle-plugin:0.9.18")

View File

@ -9,7 +9,8 @@ open class ScientifikExtension {
var vcs: String? = null var vcs: String? = null
var bintrayRepo: String? = null var bintrayRepo: String? = null
var kdoc: Boolean = true var kdoc: Boolean = true
var enableNative = false var native = false
var serialization = false
} }
internal val Project.scientifik: ScientifikExtension internal val Project.scientifik: ScientifikExtension

View File

@ -1,5 +1,6 @@
package scientifik package scientifik
import Scientifik
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
@ -7,10 +8,20 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
open class ScientifikMPPlugin : Plugin<Project> { open class ScientifikMPPlugin : Plugin<Project> {
override fun apply(project: Project) { override fun apply(project: Project) {
project.plugins.apply("org.jetbrains.kotlin.multiplatform")
val extension = project.scientifik 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<KotlinMultiplatformExtension> { project.configure<KotlinMultiplatformExtension> {
jvm { jvm {
compilations.all { compilations.all {
@ -30,7 +41,7 @@ open class ScientifikMPPlugin : Plugin<Project> {
} }
} }
if(extension.enableNative){ if (extension.native) {
linuxX64() linuxX64()
mingwX64() mingwX64()
} }
@ -39,6 +50,11 @@ open class ScientifikMPPlugin : Plugin<Project> {
val commonMain by getting { val commonMain by getting {
dependencies { dependencies {
api(kotlin("stdlib")) api(kotlin("stdlib"))
project.afterEvaluate {
if (extension.serialization) {
api("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}")
}
}
} }
} }
val commonTest by getting { val commonTest by getting {
@ -69,7 +85,8 @@ open class ScientifikMPPlugin : Plugin<Project> {
} }
} }
if(extension.enableNative){ project.afterEvaluate {
if (extension.native) {
val native by creating { val native by creating {
dependsOn(commonMain) dependsOn(commonMain)
} }
@ -81,12 +98,12 @@ open class ScientifikMPPlugin : Plugin<Project> {
} }
} }
} }
}
targets.all { targets.all {
sourceSets.all { sourceSets.all {
languageSettings.apply{ languageSettings.apply {
progressiveMode = true progressiveMode = true
this.
enableLanguageFeature("InlineClasses") enableLanguageFeature("InlineClasses")
useExperimentalAnnotation("ExperimentalUnsignedType") useExperimentalAnnotation("ExperimentalUnsignedType")
} }

View File

@ -45,12 +45,12 @@ open class ScientifikPublishPlugin : Plugin<Project> {
project.plugins.apply("maven-publish") project.plugins.apply("maven-publish")
val extension = project.scientifik val extension = project.scientifik
project.afterEvaluate {
if (extension.kdoc) { if (extension.kdoc) {
project.plugins.apply("org.jetbrains.dokka") project.plugins.apply("org.jetbrains.dokka")
} }
project.afterEvaluate {
val bintrayRepo = project.bintrayRepo val bintrayRepo = project.bintrayRepo
val vcs = project.vcs val vcs = project.vcs