gradle-tools/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt

61 lines
1.9 KiB
Kotlin
Raw Normal View History

2020-09-30 20:43:02 +03:00
package ru.mipt.npm.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
/**
* Create a separate target for node
*/
class KScienceNodePlugin : Plugin<Project> {
override fun apply(target: Project) = target.run {
//Apply multiplatform plugin is not applied, apply it
2020-11-25 14:26:08 +03:00
if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) {
2020-11-25 12:16:09 +03:00
logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically")
2020-11-25 14:26:08 +03:00
pluginManager.apply("org.jetbrains.kotlin.multiplatform")
2020-11-25 12:16:09 +03:00
}
if (plugins.findPlugin(KScienceCommonPlugin::class) == null) {
logger.info("KScience plugin is not resolved. Adding it automatically")
pluginManager.apply(KScienceCommonPlugin::class)
2020-09-30 20:43:02 +03:00
}
configure<KotlinMultiplatformExtension> {
js(name = "node", compiler = IR) {
nodejs()
}
sourceSets {
val commonMain by getting
2021-02-03 20:13:22 +03:00
val commonTest by getting
val jsCommonMain by creating{
2020-09-30 20:43:02 +03:00
dependsOn(commonMain)
2021-02-03 20:13:22 +03:00
}
val jsCommonTest by creating{
dependsOn(commonTest)
}
val jsMain by getting{
dependsOn(jsCommonMain)
}
val jsTest by getting{
dependsOn(jsCommonTest)
}
val nodeMain by creating {
dependsOn(jsCommonMain)
2020-09-30 20:43:02 +03:00
dependencies{
api("org.jetbrains.kotlinx:kotlinx-nodejs:${KScienceVersions.kotlinxNodeVersion}")
}
}
val nodeTest by creating {
2021-02-03 20:13:22 +03:00
dependsOn(jsCommonTest)
2020-09-30 20:43:02 +03:00
}
}
}
}
}