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"
version = "0.6.0-dev-5"
version = "0.6.0-dev-6"
repositories {
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.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<KotlinProjectExtension>()?.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<KotlinJsProjectExtension>()?.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<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> {
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()

View File

@ -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<Project> {
override fun apply(project: Project): Unit = project.run {
plugins.apply("org.jetbrains.kotlin.jvm")
val extension = extensions.add("kscience", KScienceExtension(this))
registerKScienceExtension()
repositories.applyRepos()

View File

@ -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<Project> {
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()

View File

@ -8,9 +8,12 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
class KScienceNativePlugin : Plugin<Project> {
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<KotlinMultiplatformExtension> {
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")

View File

@ -11,11 +11,13 @@ import org.gradle.kotlin.dsl.withType
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 githubProject: String? by project
val vcs = findProperty("vcs") as? String