From db9b4dec5055bf42882fc0664d6061d62031d333 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 13 Sep 2021 22:49:41 +0300 Subject: [PATCH] Fix plugin resolution --- build.gradle.kts | 10 ++++-- .../ru/mipt/npm/gradle/KScienceExtension.kt | 6 ++-- .../ru/mipt/npm/gradle/KScienceJSPlugin.kt | 2 +- .../ru/mipt/npm/gradle/KScienceJVMPlugin.kt | 2 +- .../ru/mipt/npm/gradle/KScienceMPPlugin.kt | 6 ++-- .../mipt/npm/gradle/KScienceNativePlugin.kt | 2 +- .../ru/mipt/npm/gradle/KScienceNodePlugin.kt | 7 ++--- .../ru/mipt/npm/gradle/KScienceVersions.kt | 31 ++++++++++--------- src/test/kotlin/TestVersions.kt | 10 ++++++ 9 files changed, 46 insertions(+), 30 deletions(-) create mode 100644 src/test/kotlin/TestVersions.kt diff --git a/build.gradle.kts b/build.gradle.kts index 94174e6..747c39e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,8 +21,6 @@ repositories { maven("https://repo.kotlin.link") } -val kotlinVersion = "1.5.30" - java.targetCompatibility = JavaVersion.VERSION_11 kotlin.explicitApiWarning() @@ -35,6 +33,13 @@ dependencies { implementation(libs.dokka.gradle) implementation(libs.kotlin.jupyter.gradle) implementation(libs.kotlin.serialization) + implementation("org.tomlj:tomlj:1.0.0") + + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() } //declaring exported plugins @@ -203,5 +208,6 @@ afterEvaluate { } tasks.processResources.configure { + duplicatesStrategy = org.gradle.api.file.DuplicatesStrategy.INCLUDE from("gradle/libs.versions.toml") } \ No newline at end of file diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt index 6c07f48..747a768 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt @@ -82,7 +82,7 @@ public class KScienceExtension(public val project: Project) { configuration: DependencyConfiguration = DependencyConfiguration.API, block: SerializationTargets.() -> Unit = {}, ): Unit = project.run { - apply("org.jetbrains.kotlin.plugin.serialization") + plugins.apply("org.jetbrains.kotlin.plugin.serialization") val artifactName = if (version.startsWith("0")) { "kotlinx-serialization-runtime" } else { @@ -137,14 +137,14 @@ public class KScienceExtension(public val project: Project) { */ @Deprecated("Use jupyterLibrary") public fun useJupyter() { - project.apply("org.jetbrains.kotlin.jupyter.api") + project.plugins.apply("org.jetbrains.kotlin.jupyter.api") } /** * Apply jupyter plugin and add entry point for the jupyter library */ public fun jupyterLibrary(pluginClass: String, vararg additionalPluginClasses: String) { - project.apply("org.jetbrains.kotlin.jupyter.api") + project.plugins.apply("org.jetbrains.kotlin.jupyter.api") project.tasks.named("processJupyterApiResources", JupyterApiResourcesTask::class.java) { libraryProducers = listOf(pluginClass, *additionalPluginClasses) } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt index b44574a..dabc588 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt @@ -7,7 +7,7 @@ import org.gradle.kotlin.dsl.apply public open class KScienceJSPlugin : Plugin { override fun apply(project: Project): Unit = project.run { if (!plugins.hasPlugin("org.jetbrains.kotlin.js")) { - apply("org.jetbrains.kotlin.js") + plugins.apply("org.jetbrains.kotlin.js") } else { logger.info("Kotlin JS plugin is already present") } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt index fcfccf9..773d148 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt @@ -7,7 +7,7 @@ import org.gradle.kotlin.dsl.apply public open class KScienceJVMPlugin : Plugin { override fun apply(project: Project): Unit = project.run { if (!plugins.hasPlugin("org.jetbrains.kotlin.jvm")) - apply("org.jetbrains.kotlin.jvm") + plugins.apply("org.jetbrains.kotlin.jvm") else logger.info("Kotlin JVM plugin is already present") diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt index c4a39f1..b78ca2c 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt @@ -3,11 +3,13 @@ package ru.mipt.npm.gradle import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.apply +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin public open class KScienceMPPlugin : Plugin { override fun apply(project: Project): Unit = project.run { - if (!plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) { - apply("org.jetbrains.kotlin.multiplatform") + if (!plugins.hasPlugin(KotlinMultiplatformPlugin::class)) { + //apply() for some reason it does not work + plugins.apply("org.jetbrains.kotlin.multiplatform") } else { logger.info("Kotlin MPP plugin is already present") } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt index 12ce3c8..36c92fa 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt @@ -10,7 +10,7 @@ public class KScienceNativePlugin : Plugin { //Apply multiplatform plugin is not applied, apply it if (!plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) { logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically") - apply("org.jetbrains.kotlin.multiplatform") + plugins.apply("org.jetbrains.kotlin.multiplatform") } if (!plugins.hasPlugin(KScienceCommonPlugin::class)) { diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt index 0e3e0cc..261a337 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt @@ -2,10 +2,7 @@ package ru.mipt.npm.gradle import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.findPlugin -import org.gradle.kotlin.dsl.invoke +import org.gradle.kotlin.dsl.* import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension /** @@ -16,7 +13,7 @@ public class KScienceNodePlugin : Plugin { //Apply multiplatform plugin is not applied, apply it if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) { logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically") - apply("org.jetbrains.kotlin.multiplatform") + plugins.apply("org.jetbrains.kotlin.multiplatform") } if (plugins.findPlugin(KScienceCommonPlugin::class) == null) { diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt index 21d9094..e871acd 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt @@ -1,31 +1,32 @@ package ru.mipt.npm.gradle + import org.gradle.api.JavaVersion -import org.gradle.internal.impldep.org.tomlj.Toml +import org.tomlj.Toml /** * Build constants */ public object KScienceVersions { - private val toml = - Toml.parse(KScienceVersions.javaClass.getResource("/libs.versions.toml")!!.readText()) + private val toml by lazy { + Toml.parse(javaClass.getResource("/libs.versions.toml")!!.readText()) + } - - public val kotlinVersion: String = toml.getString("versions.kotlin")!! - public val kotlinxNodeVersion: String = toml.getString("versions.kotlinx-nodejs")!! - public val coroutinesVersion: String = toml.getString("versions.kotlinx-coroutines")!! - public val serializationVersion: String = toml.getString("versions.kotlinx-serialization")!! - public val atomicVersion: String = toml.getString("versions.atomicfu")!! - public val ktorVersion: String = toml.getString("versions.ktor")!! - public val htmlVersion: String = toml.getString("versions.kotlinx-html")!! - public val dateTimeVersion: String = toml.getString("versions.kotlinx-datetime")!! - public val jsBom: String = toml.getString("versions.jsBom")!! + public val kotlinVersion: String get() = toml.getString("versions.kotlin")!! + public val kotlinxNodeVersion: String get() = toml.getString("versions.kotlinx-nodejs")!! + public val coroutinesVersion: String get() = toml.getString("versions.kotlinx-coroutines")!! + public val serializationVersion: String get() = toml.getString("versions.kotlinx-serialization")!! + public val atomicVersion: String get() = toml.getString("versions.atomicfu")!! + public val ktorVersion: String get() = toml.getString("versions.ktor")!! + public val htmlVersion: String get() = toml.getString("versions.kotlinx-html")!! + public val dateTimeVersion: String get() = toml.getString("versions.kotlinx-datetime")!! + public val jsBom: String get() = toml.getString("versions.jsBom")!! public val JVM_TARGET: JavaVersion = JavaVersion.VERSION_11 public object Serialization { - public val xmlVersion: String = toml.getString("versions.xmlutil")!! - public val yamlKtVersion: String = toml.getString("versions.yamlkt")!! + public val xmlVersion: String get() = toml.getString("versions.xmlutil")!! + public val yamlKtVersion: String get() = toml.getString("versions.yamlkt")!! } } diff --git a/src/test/kotlin/TestVersions.kt b/src/test/kotlin/TestVersions.kt new file mode 100644 index 0000000..4d88b50 --- /dev/null +++ b/src/test/kotlin/TestVersions.kt @@ -0,0 +1,10 @@ +package ru.mipt.npm.gradle + +import org.junit.jupiter.api.Test + +class TestPlugins { + @Test + fun testVersions() { + println(KScienceVersions.coroutinesVersion) + } +} \ No newline at end of file