Separated atomic into a plugin

This commit is contained in:
Alexander Nozik 2019-07-24 16:57:35 +03:00
parent ebbd33aa75
commit e0ec9a20d7
6 changed files with 74 additions and 18 deletions

View File

@ -54,6 +54,12 @@ gradlePlugin {
description = "Pre-configured JS project" description = "Pre-configured JS project"
implementationClass = "scientifik.ScientifikJSPlugin" implementationClass = "scientifik.ScientifikJSPlugin"
} }
create("scientifik-atomic") {
id = "scientifik.atomic"
description = "Add kotlin atomic plugin to any flafor"
implementationClass = "scientifik.ScientifikAtomicPlugin"
}
} }
} }

View File

@ -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<Project> {
override fun apply(target: Project) {
with(target) {
plugins.apply("kotlinx-atomicfu")
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
project.configure<KotlinMultiplatformExtension> {
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<KotlinJvmProjectExtension> {
sourceSets["main"].apply {
dependencies {
implementation("org.jetbrains.kotlinx:atomicfu:${Scientifik.atomicfuVersion}")
}
}
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.js") {
configure<KotlinJsProjectExtension> {
sourceSets["main"].apply {
dependencies {
implementation("org.jetbrains.kotlinx:atomicfu-js:${Scientifik.atomicfuVersion}")
}
}
}
}
}
}
}

View File

@ -10,7 +10,6 @@ open class ScientifikExtension {
var bintrayRepo: String? = null var bintrayRepo: String? = null
var kdoc: Boolean = true var kdoc: Boolean = true
var serialization = false var serialization = false
var atomicfu = false
var io = false var io = false
} }

View File

@ -33,9 +33,6 @@ open class ScientifikJSPlugin : Plugin<Project> {
if (extension.serialization) { if (extension.serialization) {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}") implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}")
} }
if (extension.atomicfu) {
implementation("org.jetbrains.kotlinx:atomicfu-js:${Scientifik.atomicfuVersion}")
}
if (extension.io) { if (extension.io) {
api("org.jetbrains.kotlinx:kotlinx-io-js:${Scientifik.ioVersion}") api("org.jetbrains.kotlinx:kotlinx-io-js:${Scientifik.ioVersion}")
} }

View File

@ -16,7 +16,6 @@ open class ScientifikJVMPlugin : Plugin<Project> {
with(project) { with(project) {
plugins.apply("org.jetbrains.kotlin.jvm") plugins.apply("org.jetbrains.kotlin.jvm")
plugins.apply("kotlinx-serialization") plugins.apply("kotlinx-serialization")
plugins.apply("kotlinx-atomicfu")
repositories.applyRepos() repositories.applyRepos()
@ -36,9 +35,6 @@ open class ScientifikJVMPlugin : Plugin<Project> {
if (extension.serialization) { if (extension.serialization) {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}") implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}")
} }
if (extension.atomicfu) {
implementation("org.jetbrains.kotlinx:atomicfu:${Scientifik.atomicfuVersion}")
}
if (extension.io) { if (extension.io) {
api("org.jetbrains.kotlinx:kotlinx-io-jvm:${Scientifik.ioVersion}") api("org.jetbrains.kotlinx:kotlinx-io-jvm:${Scientifik.ioVersion}")
} }

View File

@ -14,7 +14,6 @@ open class ScientifikMPPlugin : Plugin<Project> {
project.plugins.apply("org.jetbrains.kotlin.multiplatform") project.plugins.apply("org.jetbrains.kotlin.multiplatform")
project.plugins.apply("kotlinx-serialization") project.plugins.apply("kotlinx-serialization")
project.plugins.apply("kotlinx-atomicfu")
project.repositories.applyRepos() project.repositories.applyRepos()
@ -40,9 +39,6 @@ open class ScientifikMPPlugin : Plugin<Project> {
if (extension.serialization) { if (extension.serialization) {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}") implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}")
} }
if(extension.atomicfu){
implementation("org.jetbrains.kotlinx:atomicfu-common:${Scientifik.atomicfuVersion}")
}
if(extension.io){ if(extension.io){
api("org.jetbrains.kotlinx:kotlinx-io:${Scientifik.ioVersion}") api("org.jetbrains.kotlinx:kotlinx-io:${Scientifik.ioVersion}")
} }
@ -59,9 +55,6 @@ open class ScientifikMPPlugin : Plugin<Project> {
dependencies { dependencies {
api(kotlin("stdlib-jdk8")) api(kotlin("stdlib-jdk8"))
project.afterEvaluate { project.afterEvaluate {
if (extension.atomicfu) {
implementation("org.jetbrains.kotlinx:atomicfu:${Scientifik.atomicfuVersion}")
}
if (extension.io) { if (extension.io) {
api("org.jetbrains.kotlinx:kotlinx-io-jvm:${Scientifik.ioVersion}") api("org.jetbrains.kotlinx:kotlinx-io-jvm:${Scientifik.ioVersion}")
} }
@ -78,9 +71,6 @@ open class ScientifikMPPlugin : Plugin<Project> {
dependencies { dependencies {
api(kotlin("stdlib-js")) api(kotlin("stdlib-js"))
project.afterEvaluate { project.afterEvaluate {
if (extension.atomicfu) {
implementation("org.jetbrains.kotlinx:atomicfu-common-js:${Scientifik.atomicfuVersion}")
}
if (extension.io) { if (extension.io) {
api("org.jetbrains.kotlinx:kotlinx-io-js:${Scientifik.ioVersion}") api("org.jetbrains.kotlinx:kotlinx-io-js:${Scientifik.ioVersion}")
} }