diff --git a/build.gradle.kts b/build.gradle.kts index f54b51c..5c41a17 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,6 +12,7 @@ version = "0.1.4-dev" repositories { gradlePluginPortal() jcenter() + maven("https://kotlin.bintray.com/kotlinx") maven("https://dl.bintray.com/kotlin/kotlin-eap") } @@ -21,6 +22,7 @@ val kotlinVersion = "1.3.50-eap-5" dependencies { implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") implementation("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion") + implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.12.9") 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") @@ -33,11 +35,24 @@ gradlePlugin { description = "The publication plugin for bintray and artifactory" implementationClass = "scientifik.ScientifikPublishPlugin" } + create("scientifik-mpp") { id = "scientifik.mpp" description = "Pre-configured multiplatform project" implementationClass = "scientifik.ScientifikMPPlugin" } + + create("scientifik-jvm") { + id = "scientifik.jvm" + description = "Pre-configured JVM project" + implementationClass = "scientifik.ScientifikJVMPlugin" + } + + create("scientifik-js") { + id = "scientifik.js" + description = "Pre-configured JS project" + implementationClass = "scientifik.ScientifikJSPlugin" + } } } diff --git a/src/main/kotlin/scientifik/ScientifikExtension.kt b/src/main/kotlin/scientifik/ScientifikExtension.kt index 4f1cfb8..32ca29e 100644 --- a/src/main/kotlin/scientifik/ScientifikExtension.kt +++ b/src/main/kotlin/scientifik/ScientifikExtension.kt @@ -9,8 +9,10 @@ open class ScientifikExtension { var vcs: String? = null var bintrayRepo: String? = null var kdoc: Boolean = true - var native = false + internal var native = false var serialization = false + var atomicfu = false + var io = false } internal val Project.scientifik: ScientifikExtension diff --git a/src/main/kotlin/scientifik/ScientifikJSPlugin.kt b/src/main/kotlin/scientifik/ScientifikJSPlugin.kt new file mode 100644 index 0000000..ad3e559 --- /dev/null +++ b/src/main/kotlin/scientifik/ScientifikJSPlugin.kt @@ -0,0 +1,62 @@ +package scientifik + +import Scientifik +import kotlinx.atomicfu.plugin.gradle.sourceSets +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.plugin.KotlinDependencyHandler +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet + +open class ScientifikJSPlugin : Plugin { + override fun apply(project: Project) { + val extension = project.scientifik + + with(project) { + plugins.apply("org.jetbrains.kotlin.js") + plugins.apply("kotlinx-serialization") + plugins.apply("kotlinx-atomicfu") + + + 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") + } + + configure{ + target{ + browser() + } + } + + sourceSets["main"].apply { + this as KotlinSourceSet + languageSettings.apply { + progressiveMode = true + enableLanguageFeature("InlineClasses") + useExperimentalAnnotation("ExperimentalUnsignedType") + } + } + + dependencies { + this as KotlinDependencyHandler + api(kotlin("stdlib-jdk8")) + 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}") + } + } + + } + + } +} \ No newline at end of file diff --git a/src/main/kotlin/scientifik/ScientifikJVMPlugin.kt b/src/main/kotlin/scientifik/ScientifikJVMPlugin.kt new file mode 100644 index 0000000..6a6aa8b --- /dev/null +++ b/src/main/kotlin/scientifik/ScientifikJVMPlugin.kt @@ -0,0 +1,61 @@ +package scientifik + +import Scientifik +import kotlinx.atomicfu.plugin.gradle.sourceSets +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.* +import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +open class ScientifikJVMPlugin : Plugin { + override fun apply(project: Project) { + val extension = project.scientifik + + with(project) { + plugins.apply("org.jetbrains.kotlin.jvm") + plugins.apply("kotlinx-serialization") + plugins.apply("kotlinx-atomicfu") + + 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") + } + + tasks.withType { + kotlinOptions { + jvmTarget = "1.8" + } + } + + sourceSets["main"].apply { + this as KotlinSourceSet + languageSettings.apply { + progressiveMode = true + enableLanguageFeature("InlineClasses") + useExperimentalAnnotation("ExperimentalUnsignedType") + } + } + + dependencies { + this as KotlinDependencyHandler + api(kotlin("stdlib-jdk8")) + 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}") + } + } + + } + + } +} \ No newline at end of file diff --git a/src/main/kotlin/scientifik/ScientifikMPPlugin.kt b/src/main/kotlin/scientifik/ScientifikMPPlugin.kt index 2da2efb..4b3f1b2 100644 --- a/src/main/kotlin/scientifik/ScientifikMPPlugin.kt +++ b/src/main/kotlin/scientifik/ScientifikMPPlugin.kt @@ -12,6 +12,7 @@ open class ScientifikMPPlugin : Plugin { project.plugins.apply("org.jetbrains.kotlin.multiplatform") project.plugins.apply("kotlinx-serialization") + project.plugins.apply("kotlinx-atomicfu") project.repositories { mavenCentral() @@ -30,8 +31,8 @@ open class ScientifikMPPlugin : Plugin { } } - js{ - browser{} + js { + browser {} } if (extension.native) { @@ -45,7 +46,13 @@ open class ScientifikMPPlugin : Plugin { api(kotlin("stdlib")) project.afterEvaluate { if (extension.serialization) { - api("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){ + api("org.jetbrains.kotlinx:kotlinx-io-common:${Scientifik.ioVersion}") } } } @@ -59,6 +66,12 @@ open class ScientifikMPPlugin : Plugin { val jvmMain by getting { dependencies { api(kotlin("stdlib-jdk8")) + if(extension.atomicfu){ + implementation("org.jetbrains.kotlinx:atomicfu:${Scientifik.atomicfuVersion}") + } + if(extension.io){ + api("org.jetbrains.kotlinx:kotlinx-io-jvm:${Scientifik.ioVersion}") + } } } val jvmTest by getting { @@ -70,6 +83,12 @@ open class ScientifikMPPlugin : Plugin { val jsMain by getting { dependencies { api(kotlin("stdlib-js")) + if(extension.atomicfu){ + implementation("org.jetbrains.kotlinx:atomicfu-common-js:${Scientifik.atomicfuVersion}") + } + if(extension.io){ + api("org.jetbrains.kotlinx:kotlinx-io-js:${Scientifik.ioVersion}") + } } } val jsTest by getting {