From f456be46d425b0bf87d4ad8783b502cec1389dbb Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 25 Nov 2020 12:16:09 +0300 Subject: [PATCH] Centralized logic for all plugins --- CHANGELOG.md | 4 + build.gradle.kts | 15 +- .../mipt/npm/gradle/KScienceCommonPlugin.kt | 138 ++++++++++++++++++ .../ru/mipt/npm/gradle/KScienceJSPlugin.kt | 45 +----- .../ru/mipt/npm/gradle/KScienceJVMPlugin.kt | 54 +------ .../ru/mipt/npm/gradle/KScienceMPPlugin.kt | 99 +------------ .../mipt/npm/gradle/KScienceNativePlugin.kt | 11 +- .../ru/mipt/npm/gradle/KScienceNodePlugin.kt | 11 +- .../ru/mipt/npm/gradle/KScienceVersions.kt | 8 +- ...rialization.kt => SerializationTargets.kt} | 16 ++ src/main/kotlin/ru/mipt/npm/gradle/common.kt | 1 + 11 files changed, 210 insertions(+), 192 deletions(-) create mode 100644 src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt rename src/main/kotlin/ru/mipt/npm/gradle/{serialization.kt => SerializationTargets.kt} (79%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3735e34..ef4e7dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,14 +10,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Changelog plugin automatically applied to `project`. - Feature matrix and Readme generation task for a `project` plugin. - Add `binary-compatibility-validator` to the `project` plugin. +- Separate `yamlKt` serialization target +- Separate `ain` plugin ### Changed - Remove node plugin. Node binaries should be turned on manually. - Use default webpack distribution path. - `ru.mipt.npm.base` -> `ru.mipt.npm.project`. - Move publishing out of general extension and apply it to project plugin instead. +- Platform plugins are now simple references to common plugin ### Deprecated +- Support of `kaml` and `snake-yaml` in favor of `yamlKt` ### Removed - Node plugin. diff --git a/build.gradle.kts b/build.gradle.kts index 20b5880..8317e59 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "ru.mipt.npm" -version = "0.6.4-dev-1.4.20-M2" +version = "0.7.0" repositories { gradlePluginPortal() @@ -16,7 +16,7 @@ repositories { maven("https://dl.bintray.com/kotlin/kotlin-dev") } -val kotlinVersion = "1.4.20-M2" +val kotlinVersion = "1.4.20" java { targetCompatibility = JavaVersion.VERSION_1_8 @@ -27,14 +27,19 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") implementation("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion") implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.14.4") - implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.4.10") + implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.4.10.2") implementation("org.jetbrains.dokka:dokka-base:1.4.10") - implementation("org.jetbrains.intellij.plugins:gradle-changelog-plugin:0.5.0") - implementation("org.jetbrains.kotlinx:binary-compatibility-validator:0.2.3") + implementation("org.jetbrains.intellij.plugins:gradle-changelog-plugin:0.6.2") + implementation("org.jetbrains.kotlinx:binary-compatibility-validator:0.2.4") } gradlePlugin { plugins { + create("kscience.common"){ + id = "ru.mipt.npm.kscience" + description = "The generalized kscience plugin that works in conjunction with any kotlin plugin" + implementationClass = "ru.mipt.npm.gradle.KScienceCommonPlugin" + } create("kscience.project"){ id = "ru.mipt.npm.project" description = "The root plugin for multimodule project infrastructure" diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt new file mode 100644 index 0000000..124926c --- /dev/null +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt @@ -0,0 +1,138 @@ +package ru.mipt.npm.gradle + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.plugins.JavaPluginExtension +import org.gradle.api.tasks.Copy +import org.gradle.api.tasks.testing.Test +import org.gradle.kotlin.dsl.* +import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension + +open class KScienceCommonPlugin : Plugin { + override fun apply(project: Project): Unit = project.run { + //Common configuration + registerKScienceExtension() + repositories.applyRepos() + + //Configuration for K-JVM plugin + pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { + configure { + explicitApiWarning() + + sourceSets["main"].apply { + languageSettings.applySettings() + } + + sourceSets["test"].apply { + languageSettings.applySettings() + dependencies { + implementation(kotlin("test-junit5")) + implementation("org.junit.jupiter:junit-jupiter:5.6.1") + } + } + } + } + + pluginManager.withPlugin("org.jetbrains.kotlin.js") { + configure { + explicitApiWarning() + + js(IR) { + browser() + } + + sourceSets["main"].apply { + languageSettings.applySettings() + } + + sourceSets["test"].apply { + languageSettings.applySettings() + dependencies { + implementation(kotlin("test-js")) + } + } + } + } + + pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { + configure { + explicitApiWarning() + + jvm { + compilations.all { + kotlinOptions { +// useIR = true + jvmTarget = KScienceVersions.JVM_TARGET.toString() + } + } + } + + js(IR) { + browser() + } + + sourceSets.invoke { + val commonMain by getting + val commonTest by getting { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + } + } + val jvmMain by getting + val jvmTest by getting { + dependencies { + implementation(kotlin("test-junit5")) + implementation("org.junit.jupiter:junit-jupiter:5.6.1") + } + } + val jsMain by getting + val jsTest by getting { + dependencies { + implementation(kotlin("test-js")) + } + } + } + + afterEvaluate { + targets.all { + sourceSets.all { + languageSettings.applySettings() + } + } + } + } + } + + afterEvaluate { + extensions.findByType()?.apply { + targetCompatibility = KScienceVersions.JVM_TARGET + withSourcesJar() + //withJavadocJar() + } + + tasks.apply { + withType { + kotlinOptions { +// useIR = true + jvmTarget = KScienceVersions.JVM_TARGET.toString() + } + } + withType { + useJUnitPlatform() + } + + (findByName("processResources") as? Copy)?.apply { + fromDependencies("runtimeClasspath") + } + + (findByName("jsProcessResources") as? Copy)?.apply { + fromDependencies("jsRuntimeClasspath") + } + } + } + } +} diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt index 579abc6..75de0f4 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt @@ -2,48 +2,15 @@ package ru.mipt.npm.gradle import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.tasks.Copy -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.get -import org.gradle.kotlin.dsl.getValue -import org.gradle.kotlin.dsl.getting -import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension +import org.gradle.kotlin.dsl.apply open class KScienceJSPlugin : Plugin { override fun apply(project: Project): Unit = project.run { - plugins.apply("org.jetbrains.kotlin.js") - registerKScienceExtension() - - repositories.applyRepos() - - configure { - explicitApiWarning() - - js(IR) { - browser() - } - - sourceSets["main"].apply { - languageSettings.applySettings() - - dependencies { - api(kotlin("stdlib-js")) - } - } - - sourceSets["test"].apply { - languageSettings.applySettings() - dependencies { - implementation(kotlin("test-js")) - } - } - } - - tasks.apply { - val processResources by getting(Copy::class) { - fromDependencies("runtimeClasspath") - } + if (plugins.findPlugin("org.jetbrains.kotlin.js") == null) { + pluginManager.apply("org.jetbrains.kotlin.js") + } else { + logger.info("Kotlin JS plugin is already present") } + plugins.apply(KScienceCommonPlugin::class) } - } \ No newline at end of file diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt index 6367268..eaaab4d 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt @@ -2,58 +2,16 @@ package ru.mipt.npm.gradle import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.plugins.JavaPluginExtension -import org.gradle.api.tasks.testing.Test -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.findByType -import org.gradle.kotlin.dsl.get -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.gradle.kotlin.dsl.apply open class KScienceJVMPlugin : Plugin { override fun apply(project: Project): Unit = project.run { - plugins.apply("org.jetbrains.kotlin.jvm") - registerKScienceExtension() - - repositories.applyRepos() - - extensions.findByType()?.apply { - targetCompatibility = KScienceVersions.JVM_TARGET - withSourcesJar() - //withJavadocJar() - } - - tasks.withType { - kotlinOptions { -// useIR = true - jvmTarget = KScienceVersions.JVM_TARGET.toString() - } - } - - configure { - explicitApiWarning() - val sourceSet = sourceSets["main"].apply { - languageSettings.applySettings() - } - - sourceSets["test"].apply { - languageSettings.applySettings() - dependencies { - implementation(kotlin("test-junit5")) - implementation("org.junit.jupiter:junit-jupiter:5.6.1") - } - } - } - - tasks.apply { - withType() { - useJUnitPlatform() - } -// -// val processResources by getting(Copy::class) -// processResources.copyJVMResources(configurations["runtimeClasspath"]) + if (plugins.findPlugin("org.jetbrains.kotlin.jvm") == null) { + pluginManager.apply("org.jetbrains.kotlin.jvm") + } else { + logger.info("Kotlin JVM plugin is already present") } + plugins.apply(KScienceCommonPlugin::class) } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt index bebd47a..ef0a7de 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt @@ -2,99 +2,16 @@ package ru.mipt.npm.gradle import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.tasks.Copy -import org.gradle.api.tasks.testing.Test -import org.gradle.kotlin.dsl.* -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.findPlugin +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin open class KScienceMPPlugin : Plugin { override fun apply(project: Project): Unit = project.run { - plugins.apply("org.jetbrains.kotlin.multiplatform") - registerKScienceExtension() - repositories.applyRepos() - - configure { - explicitApiWarning() - - jvm { - compilations.all { - kotlinOptions { -// useIR = true - jvmTarget = KScienceVersions.JVM_TARGET.toString() - } - } - } - - js(IR) { - browser() - } - - sourceSets.invoke { - val commonMain by getting - val commonTest by getting { - dependencies { - implementation(kotlin("test-common")) - implementation(kotlin("test-annotations-common")) - } - } - val jvmMain by getting - val jvmTest by getting { - dependencies { - implementation(kotlin("test-junit5")) - implementation("org.junit.jupiter:junit-jupiter:5.6.1") - } - } - val jsMain by getting - val jsTest by getting { - dependencies { - implementation(kotlin("test-js")) - } - } - } - - afterEvaluate { - targets.all { - sourceSets.all { - languageSettings.applySettings() - } - } - } - -// pluginManager.withPlugin("org.jetbrains.dokka") { -// logger.info("Adding dokka functionality to project ${this@run.name}") -// -// val dokkaHtml by tasks.getting(DokkaTask::class) { -// dokkaSourceSets { -// register("commonMain") { -// displayName = "common" -// platform = "common" -// } -// register("jvmMain") { -// displayName = "jvm" -// platform = "jvm" -// } -// register("jsMain") { -// displayName = "js" -// platform = "js" -// } -// configureEach { -// jdkVersion = 11 -// } -// } -// } -// } - - tasks.apply { - withType { - useJUnitPlatform() - } - - val jsProcessResources by getting(Copy::class) { - fromDependencies("jsRuntimeClasspath") - } - - } - + if (plugins.findPlugin(KotlinMultiplatformPlugin::class) == null) { + logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically") + pluginManager.apply(KotlinMultiplatformPlugin::class) } - } + plugins.apply(KScienceCommonPlugin::class) + } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt index 6169787..80c5cdf 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt @@ -5,13 +5,18 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.* import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin class KScienceNativePlugin : Plugin { override fun apply(target: Project) = target.run { //Apply multiplatform plugin is not applied, apply it - if (plugins.findPlugin(KScienceMPPlugin::class) == null) { - logger.info("Multiplatform KScience plugin is not resolved. Adding it automatically") - pluginManager.apply(KScienceMPPlugin::class) + if (plugins.findPlugin(KotlinMultiplatformPlugin::class) == null) { + logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically") + pluginManager.apply(KotlinMultiplatformPlugin::class) + } + if (plugins.findPlugin(KScienceCommonPlugin::class) == null) { + logger.info("KScience plugin is not resolved. Adding it automatically") + pluginManager.apply(KScienceCommonPlugin::class) } configure { diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt index 66ea1c9..a65229c 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt @@ -4,6 +4,7 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.* import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin /** * Create a separate target for node @@ -11,9 +12,13 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension class KScienceNodePlugin : Plugin { override fun apply(target: Project) = target.run { //Apply multiplatform plugin is not applied, apply it - if (plugins.findPlugin(KScienceMPPlugin::class) == null) { - logger.info("Multiplatform KScience plugin is not resolved. Adding it automatically") - pluginManager.apply(KScienceMPPlugin::class) + if (plugins.findPlugin(KotlinMultiplatformPlugin::class) == null) { + logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically") + pluginManager.apply(KotlinMultiplatformPlugin::class) + } + if (plugins.findPlugin(KScienceCommonPlugin::class) == null) { + logger.info("KScience plugin is not resolved. Adding it automatically") + pluginManager.apply(KScienceCommonPlugin::class) } configure { diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt index 0144c66..4cf4049 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt @@ -6,17 +6,19 @@ import org.gradle.api.JavaVersion * Build constants */ object KScienceVersions { - const val kotlinVersion = "1.4.20-M2" + const val kotlinVersion = "1.4.20" const val kotlinxNodeVersion = "0.0.7" - const val coroutinesVersion = "1.3.9" - const val serializationVersion = "1.0.0" + const val coroutinesVersion = "1.4.1" + const val serializationVersion = "1.0.1" const val atomicVersion = "0.14.4" val JVM_TARGET = JavaVersion.VERSION_11 object Serialization{ const val xmlVersion = "0.80.1" + @Deprecated("Use yamlKt instead") const val yamlVersion = "0.21.0" const val bsonVersion = "0.4.2" + const val yamlKtVersion = "0.7.4" } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/serialization.kt b/src/main/kotlin/ru/mipt/npm/gradle/SerializationTargets.kt similarity index 79% rename from src/main/kotlin/ru/mipt/npm/gradle/serialization.kt rename to src/main/kotlin/ru/mipt/npm/gradle/SerializationTargets.kt index b0859f3..dc762f6 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/serialization.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/SerializationTargets.kt @@ -1,6 +1,8 @@ package ru.mipt.npm.gradle import org.gradle.api.Project +import org.gradle.kotlin.dsl.maven +import org.gradle.kotlin.dsl.repositories class SerializationTargets( val sourceSet: DependencySourceSet, @@ -40,6 +42,9 @@ class SerializationTargets( fun Project.xml( version: String = KScienceVersions.Serialization.xmlVersion ) { + repositories { + maven("https://dl.bintray.com/pdvrieze/maven") + } useCommonDependency( "net.devrieze:xmlutil-serialization:$version", dependencySourceSet = sourceSet, @@ -47,6 +52,7 @@ class SerializationTargets( ) } + @Deprecated("Use multiplatform yamlKt instead") fun Project.yaml( version: String = KScienceVersions.Serialization.yamlVersion ) { @@ -57,6 +63,16 @@ class SerializationTargets( ) } + fun Project.yamlKt( + version: String = KScienceVersions.Serialization.yamlVersion + ) { + useCommonDependency( + "net.mamoe.yamlkt:yamlkt:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration + ) + } + fun Project.bson( version: String = KScienceVersions.Serialization.bsonVersion ) { diff --git a/src/main/kotlin/ru/mipt/npm/gradle/common.kt b/src/main/kotlin/ru/mipt/npm/gradle/common.kt index 1cbfebc..790296e 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/common.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/common.kt @@ -15,6 +15,7 @@ internal fun LanguageSettingsBuilder.applySettings(): Unit { useExperimentalAnnotation("kotlin.ExperimentalStdlibApi") useExperimentalAnnotation("kotlin.time.ExperimentalTime") useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") + useExperimentalAnnotation("kotlin.js.ExperimentalJsExport") } internal fun RepositoryHandler.applyRepos(): Unit {