Safe extension resolution.

Executables for native.
This commit is contained in:
Alexander Nozik 2020-09-09 11:40:49 +03:00
parent 385fbb2ac4
commit b6c984db84
7 changed files with 24 additions and 10 deletions

View File

@ -6,7 +6,7 @@ plugins {
} }
group = "ru.mipt.npm" group = "ru.mipt.npm"
version = "0.6.0-dev-5" version = "0.6.0-dev-6"
repositories { repositories {
gradlePluginPortal() gradlePluginPortal()

View File

@ -5,6 +5,7 @@ import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
class KScienceExtension(val project: Project) { class KScienceExtension(val project: Project) {
@ -81,9 +82,13 @@ class KScienceExtension(val project: Project) {
js { js {
binaries.executable() binaries.executable()
} }
(targets.findByName("native") as? KotlinNativeTarget)?.apply {
binaries.executable()
} }
} }
}
/** /**
* Activate publishing and configure it * Activate publishing and configure it
*/ */
@ -107,3 +112,9 @@ class KScienceExtension(val project: Project) {
var bintrayRepo: String? by project.extra var bintrayRepo: String? by project.extra
} }
} }
internal fun Project.registerKScienceExtension() {
if (extensions.findByType<KScienceExtension>() == null) {
extensions.add("kscience", KScienceExtension(this))
}
}

View File

@ -12,7 +12,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
open class KScienceJSPlugin : Plugin<Project> { open class KScienceJSPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { override fun apply(project: Project): Unit = project.run {
plugins.apply("org.jetbrains.kotlin.js") plugins.apply("org.jetbrains.kotlin.js")
val extension = extensions.add("kscience", KScienceExtension(this)) extensions.add("kscience", KScienceExtension(this))
repositories.applyRepos() repositories.applyRepos()

View File

@ -9,14 +9,13 @@ import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.testing.Test import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
open class KScienceJVMPlugin : Plugin<Project> { open class KScienceJVMPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { override fun apply(project: Project): Unit = project.run {
plugins.apply("org.jetbrains.kotlin.jvm") plugins.apply("org.jetbrains.kotlin.jvm")
val extension = extensions.add("kscience", KScienceExtension(this)) registerKScienceExtension()
repositories.applyRepos() repositories.applyRepos()

View File

@ -5,14 +5,13 @@ import org.gradle.api.Project
import org.gradle.api.tasks.Copy import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.testing.Test import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
open class KScienceMPPlugin : Plugin<Project> { open class KScienceMPPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { override fun apply(project: Project): Unit = project.run {
plugins.apply("org.jetbrains.kotlin.multiplatform") plugins.apply("org.jetbrains.kotlin.multiplatform")
val extension = extensions.add("kscience", KScienceExtension(this)) extensions.add("kscience", KScienceExtension(this))
repositories.applyRepos() repositories.applyRepos()

View File

@ -8,9 +8,12 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
class KScienceNativePlugin : Plugin<Project> { class KScienceNativePlugin : Plugin<Project> {
override fun apply(target: Project) = target.run { override fun apply(target: Project) = target.run {
//Apply multiplatform plugin is not applied, apply it
if (plugins.findPlugin(KScienceMPPlugin::class) == null) { if (plugins.findPlugin(KScienceMPPlugin::class) == null) {
logger.info("Multiplatform KScience plugin is not resolved. Adding it automatically")
pluginManager.apply(KScienceMPPlugin::class) pluginManager.apply(KScienceMPPlugin::class)
} }
configure<KotlinMultiplatformExtension> { configure<KotlinMultiplatformExtension> {
val hostOs = System.getProperty("os.name") val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows") val isMingwX64 = hostOs.startsWith("Windows")

View File

@ -11,11 +11,13 @@ import org.gradle.kotlin.dsl.withType
open class KSciencePublishPlugin : Plugin<Project> { open class KSciencePublishPlugin : Plugin<Project> {
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 githubOrg: String = project.findProperty("githubOrg") as? String ?: "mipt-npm"
val githubProject: String? by project val githubProject: String? by project
val vcs = findProperty("vcs") as? String val vcs = findProperty("vcs") as? String