From b6c984db848b7c99d7d4bb321acaa5412dd50254 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 9 Sep 2020 11:40:49 +0300 Subject: [PATCH] Safe extension resolution. Executables for native. --- build.gradle.kts | 2 +- .../kotlin/ru/mipt/npm/gradle/KScienceExtension.kt | 13 ++++++++++++- .../kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt | 2 +- .../kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt | 3 +-- .../kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt | 3 +-- .../ru/mipt/npm/gradle/KScienceNativePlugin.kt | 3 +++ .../ru/mipt/npm/gradle/KSciencePublishPlugin.kt | 8 +++++--- 7 files changed, 24 insertions(+), 10 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6a2d37d..8af89de 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "ru.mipt.npm" -version = "0.6.0-dev-5" +version = "0.6.0-dev-6" repositories { gradlePluginPortal() diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt index 6cb2242..0a19219 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt @@ -5,6 +5,7 @@ import org.gradle.kotlin.dsl.* import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget class KScienceExtension(val project: Project) { @@ -69,7 +70,7 @@ class KScienceExtension(val project: Project) { project.extensions.findByType()?.apply { explicitApi = null } - project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm"){ + project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { project.plugins.apply("org.gradle.application") } project.extensions.findByType()?.apply { @@ -81,7 +82,11 @@ class KScienceExtension(val project: Project) { js { binaries.executable() } + (targets.findByName("native") as? KotlinNativeTarget)?.apply { + binaries.executable() + } } + } /** @@ -106,4 +111,10 @@ class KScienceExtension(val project: Project) { var bintrayApiKey: String? by project.extra var bintrayRepo: String? by project.extra } +} + +internal fun Project.registerKScienceExtension() { + if (extensions.findByType() == null) { + extensions.add("kscience", KScienceExtension(this)) + } } \ No newline at end of file diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt index 0813c27..3b000e8 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt @@ -12,7 +12,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension open class KScienceJSPlugin : Plugin { override fun apply(project: Project): Unit = project.run { plugins.apply("org.jetbrains.kotlin.js") - val extension = extensions.add("kscience", KScienceExtension(this)) + extensions.add("kscience", KScienceExtension(this)) repositories.applyRepos() diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt index bac301f..0c6d26e 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt @@ -9,14 +9,13 @@ import org.gradle.api.tasks.Copy import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.testing.Test import org.gradle.kotlin.dsl.* -import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.tasks.KotlinCompile open class KScienceJVMPlugin : Plugin { override fun apply(project: Project): Unit = project.run { plugins.apply("org.jetbrains.kotlin.jvm") - val extension = extensions.add("kscience", KScienceExtension(this)) + registerKScienceExtension() repositories.applyRepos() diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt index 63e40c9..deb6bfd 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt @@ -5,14 +5,13 @@ 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.dokka.gradle.DokkaTask import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension open class KScienceMPPlugin : Plugin { override fun apply(project: Project): Unit = project.run { plugins.apply("org.jetbrains.kotlin.multiplatform") - val extension = extensions.add("kscience", KScienceExtension(this)) + extensions.add("kscience", KScienceExtension(this)) repositories.applyRepos() diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt index 26579e6..664ce68 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt @@ -8,9 +8,12 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension 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) } + configure { val hostOs = System.getProperty("os.name") val isMingwX64 = hostOs.startsWith("Windows") diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt index f08f59c..13db04a 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt @@ -11,11 +11,13 @@ import org.gradle.kotlin.dsl.withType open class KSciencePublishPlugin : Plugin { - override fun apply(project: Project) { + override fun apply(project: Project): Unit = project.run{ - project.plugins.apply("maven-publish") + plugins.apply("maven-publish") - project.afterEvaluate { + registerKScienceExtension() + + afterEvaluate { val githubOrg: String = project.findProperty("githubOrg") as? String ?: "mipt-npm" val githubProject: String? by project val vcs = findProperty("vcs") as? String