From e0ec9a20d76695251a2ada54585046c0128e877c Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 24 Jul 2019 16:57:35 +0300 Subject: [PATCH] Separated atomic into a plugin --- build.gradle.kts | 6 ++ .../scientifik/ScientifikAtomicPlugin.kt | 68 +++++++++++++++++++ .../kotlin/scientifik/ScientifikExtension.kt | 1 - .../kotlin/scientifik/ScientifikJSPlugin.kt | 3 - .../kotlin/scientifik/ScientifikJVMPlugin.kt | 4 -- .../kotlin/scientifik/ScientifikMPPlugin.kt | 10 --- 6 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 src/main/kotlin/scientifik/ScientifikAtomicPlugin.kt diff --git a/build.gradle.kts b/build.gradle.kts index eb4643d..ccaacba 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -54,6 +54,12 @@ gradlePlugin { description = "Pre-configured JS project" implementationClass = "scientifik.ScientifikJSPlugin" } + + create("scientifik-atomic") { + id = "scientifik.atomic" + description = "Add kotlin atomic plugin to any flafor" + implementationClass = "scientifik.ScientifikAtomicPlugin" + } } } diff --git a/src/main/kotlin/scientifik/ScientifikAtomicPlugin.kt b/src/main/kotlin/scientifik/ScientifikAtomicPlugin.kt new file mode 100644 index 0000000..36a72f3 --- /dev/null +++ b/src/main/kotlin/scientifik/ScientifikAtomicPlugin.kt @@ -0,0 +1,68 @@ +package scientifik + +import Scientifik +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.* +import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension + +class ScientifikAtomicPlugin : Plugin { + override fun apply(target: Project) { + with(target) { + plugins.apply("kotlinx-atomicfu") + + pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { + project.configure { + sourceSets.invoke { + val commonMain by getting { + dependencies { + implementation("org.jetbrains.kotlinx:atomicfu-common:${Scientifik.atomicfuVersion}") + } + } + + val jvmMain by getting { + dependencies { + implementation("org.jetbrains.kotlinx:atomicfu:${Scientifik.atomicfuVersion}") + } + } + val jsMain by getting { + dependencies { + implementation("org.jetbrains.kotlinx:atomicfu-common-js:${Scientifik.atomicfuVersion}") + } + } + val jsTest by getting { + dependencies { + implementation(kotlin("test-js")) + } + } + } + } + //TODO add native clause + } + + pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { + configure { + sourceSets["main"].apply { + dependencies { + implementation("org.jetbrains.kotlinx:atomicfu:${Scientifik.atomicfuVersion}") + } + } + } + } + + pluginManager.withPlugin("org.jetbrains.kotlin.js") { + configure { + sourceSets["main"].apply { + dependencies { + implementation("org.jetbrains.kotlinx:atomicfu-js:${Scientifik.atomicfuVersion}") + } + } + } + } + } + } +} + + diff --git a/src/main/kotlin/scientifik/ScientifikExtension.kt b/src/main/kotlin/scientifik/ScientifikExtension.kt index 5b59291..49e8e61 100644 --- a/src/main/kotlin/scientifik/ScientifikExtension.kt +++ b/src/main/kotlin/scientifik/ScientifikExtension.kt @@ -10,7 +10,6 @@ open class ScientifikExtension { var bintrayRepo: String? = null var kdoc: Boolean = true var serialization = false - var atomicfu = false var io = false } diff --git a/src/main/kotlin/scientifik/ScientifikJSPlugin.kt b/src/main/kotlin/scientifik/ScientifikJSPlugin.kt index a6833eb..5fc4279 100644 --- a/src/main/kotlin/scientifik/ScientifikJSPlugin.kt +++ b/src/main/kotlin/scientifik/ScientifikJSPlugin.kt @@ -33,9 +33,6 @@ open class ScientifikJSPlugin : Plugin { if (extension.serialization) { implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}") } - if (extension.atomicfu) { - implementation("org.jetbrains.kotlinx:atomicfu-js:${Scientifik.atomicfuVersion}") - } 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 3b4f1c2..02404bf 100644 --- a/src/main/kotlin/scientifik/ScientifikJVMPlugin.kt +++ b/src/main/kotlin/scientifik/ScientifikJVMPlugin.kt @@ -16,7 +16,6 @@ open class ScientifikJVMPlugin : Plugin { with(project) { plugins.apply("org.jetbrains.kotlin.jvm") plugins.apply("kotlinx-serialization") - plugins.apply("kotlinx-atomicfu") repositories.applyRepos() @@ -36,9 +35,6 @@ open class ScientifikJVMPlugin : Plugin { if (extension.serialization) { implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}") } - if (extension.atomicfu) { - implementation("org.jetbrains.kotlinx:atomicfu:${Scientifik.atomicfuVersion}") - } 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 eb2145c..e95deb9 100644 --- a/src/main/kotlin/scientifik/ScientifikMPPlugin.kt +++ b/src/main/kotlin/scientifik/ScientifikMPPlugin.kt @@ -14,7 +14,6 @@ open class ScientifikMPPlugin : Plugin { project.plugins.apply("org.jetbrains.kotlin.multiplatform") project.plugins.apply("kotlinx-serialization") - project.plugins.apply("kotlinx-atomicfu") project.repositories.applyRepos() @@ -40,9 +39,6 @@ open class ScientifikMPPlugin : Plugin { if (extension.serialization) { implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}") } - if(extension.atomicfu){ - implementation("org.jetbrains.kotlinx:atomicfu-common:${Scientifik.atomicfuVersion}") - } if(extension.io){ api("org.jetbrains.kotlinx:kotlinx-io:${Scientifik.ioVersion}") } @@ -59,9 +55,6 @@ open class ScientifikMPPlugin : Plugin { dependencies { api(kotlin("stdlib-jdk8")) project.afterEvaluate { - if (extension.atomicfu) { - implementation("org.jetbrains.kotlinx:atomicfu:${Scientifik.atomicfuVersion}") - } if (extension.io) { api("org.jetbrains.kotlinx:kotlinx-io-jvm:${Scientifik.ioVersion}") } @@ -78,9 +71,6 @@ open class ScientifikMPPlugin : Plugin { dependencies { api(kotlin("stdlib-js")) project.afterEvaluate { - if (extension.atomicfu) { - implementation("org.jetbrains.kotlinx:atomicfu-common-js:${Scientifik.atomicfuVersion}") - } if (extension.io) { api("org.jetbrains.kotlinx:kotlinx-io-js:${Scientifik.ioVersion}") }