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
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")

View File

@ -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

View File

@ -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<Project> {
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<KotlinMultiplatformExtension> {
jvm {
compilations.all {
@ -30,7 +41,7 @@ open class ScientifikMPPlugin : Plugin<Project> {
}
}
if(extension.enableNative){
if (extension.native) {
linuxX64()
mingwX64()
}
@ -39,6 +50,11 @@ open class ScientifikMPPlugin : Plugin<Project> {
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<Project> {
}
}
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")
}

View File

@ -45,12 +45,12 @@ open class ScientifikPublishPlugin : Plugin<Project> {
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