2020-08-20 10:02:28 +03:00
|
|
|
package ru.mipt.npm.gradle
|
2019-06-28 16:22:11 +03:00
|
|
|
|
|
|
|
import org.gradle.api.Plugin
|
|
|
|
import org.gradle.api.Project
|
2020-05-04 19:57:27 +03:00
|
|
|
import org.gradle.api.tasks.Copy
|
2020-04-07 12:49:40 +03:00
|
|
|
import org.gradle.api.tasks.testing.Test
|
2019-07-17 16:04:39 +03:00
|
|
|
import org.gradle.kotlin.dsl.*
|
2019-06-28 16:22:11 +03:00
|
|
|
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
|
|
|
|
2020-08-20 10:02:28 +03:00
|
|
|
open class KScienceMPPlugin : Plugin<Project> {
|
2020-07-05 14:39:35 +03:00
|
|
|
override fun apply(project: Project): Unit = project.run {
|
|
|
|
plugins.apply("org.jetbrains.kotlin.multiplatform")
|
2020-09-10 11:38:57 +03:00
|
|
|
registerKScienceExtension()
|
2020-07-05 14:39:35 +03:00
|
|
|
repositories.applyRepos()
|
2019-08-09 11:51:30 +03:00
|
|
|
|
2020-07-05 14:39:35 +03:00
|
|
|
configure<KotlinMultiplatformExtension> {
|
2020-08-20 10:02:28 +03:00
|
|
|
explicitApiWarning()
|
2020-03-14 14:42:11 +03:00
|
|
|
|
2020-07-05 14:39:35 +03:00
|
|
|
jvm {
|
|
|
|
compilations.all {
|
|
|
|
kotlinOptions {
|
2020-08-31 12:40:13 +03:00
|
|
|
// useIR = true
|
2020-08-20 10:02:28 +03:00
|
|
|
jvmTarget = KScienceVersions.JVM_TARGET.toString()
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
|
|
|
}
|
2020-07-05 14:39:35 +03:00
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
|
2020-08-20 10:02:28 +03:00
|
|
|
js(IR) {
|
2020-09-22 16:21:09 +03:00
|
|
|
browser()
|
2020-07-05 14:39:35 +03:00
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
|
2020-07-05 14:39:35 +03:00
|
|
|
sourceSets.invoke {
|
2020-08-20 10:02:28 +03:00
|
|
|
val commonMain by getting
|
2020-07-05 14:39:35 +03:00
|
|
|
val commonTest by getting {
|
|
|
|
dependencies {
|
|
|
|
implementation(kotlin("test-common"))
|
|
|
|
implementation(kotlin("test-annotations-common"))
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
2020-07-05 14:39:35 +03:00
|
|
|
}
|
2020-08-20 10:02:28 +03:00
|
|
|
val jvmMain by getting
|
2020-07-05 14:39:35 +03:00
|
|
|
val jvmTest by getting {
|
|
|
|
dependencies {
|
|
|
|
implementation(kotlin("test-junit5"))
|
|
|
|
implementation("org.junit.jupiter:junit-jupiter:5.6.1")
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
2020-07-05 14:39:35 +03:00
|
|
|
}
|
2020-08-20 10:02:28 +03:00
|
|
|
val jsMain by getting
|
2020-07-05 14:39:35 +03:00
|
|
|
val jsTest by getting {
|
|
|
|
dependencies {
|
|
|
|
implementation(kotlin("test-js"))
|
2019-08-09 11:51:30 +03:00
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
2020-07-05 14:39:35 +03:00
|
|
|
}
|
2019-08-09 11:51:30 +03:00
|
|
|
|
2020-08-31 12:40:13 +03:00
|
|
|
afterEvaluate {
|
|
|
|
targets.all {
|
|
|
|
sourceSets.all {
|
|
|
|
languageSettings.applySettings()
|
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
2020-07-05 14:39:35 +03:00
|
|
|
}
|
2019-07-24 15:03:12 +03:00
|
|
|
|
2020-09-05 14:17:04 +03:00
|
|
|
// pluginManager.withPlugin("org.jetbrains.dokka") {
|
|
|
|
// logger.info("Adding dokka functionality to project ${this@run.name}")
|
|
|
|
//
|
|
|
|
// val dokkaHtml by tasks.getting(DokkaTask::class) {
|
|
|
|
// dokkaSourceSets {
|
|
|
|
// register("commonMain") {
|
|
|
|
// displayName = "common"
|
|
|
|
// platform = "common"
|
|
|
|
// }
|
|
|
|
// register("jvmMain") {
|
|
|
|
// displayName = "jvm"
|
|
|
|
// platform = "jvm"
|
|
|
|
// }
|
|
|
|
// register("jsMain") {
|
|
|
|
// displayName = "js"
|
|
|
|
// platform = "js"
|
|
|
|
// }
|
|
|
|
// configureEach {
|
|
|
|
// jdkVersion = 11
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2019-07-17 16:04:39 +03:00
|
|
|
|
2020-07-05 14:39:35 +03:00
|
|
|
tasks.apply {
|
2020-09-22 16:21:09 +03:00
|
|
|
withType<Test> {
|
2020-07-06 09:52:54 +03:00
|
|
|
useJUnitPlatform()
|
|
|
|
}
|
|
|
|
|
2020-07-05 14:39:35 +03:00
|
|
|
val jsProcessResources by getting(Copy::class)
|
|
|
|
jsProcessResources.copyJSResources(configurations["jsRuntimeClasspath"])
|
2019-12-30 17:02:12 +03:00
|
|
|
|
2020-07-06 09:52:54 +03:00
|
|
|
val jvmProcessResources by getting(Copy::class)
|
|
|
|
jvmProcessResources.copyJVMResources(configurations["jvmRuntimeClasspath"])
|
|
|
|
|
2020-08-20 10:02:28 +03:00
|
|
|
findByName("jsBrowserDistribution")?.apply {
|
2020-07-05 14:39:35 +03:00
|
|
|
doLast {
|
|
|
|
val indexFile = project.jsDistDirectory.resolve("index.html")
|
|
|
|
if (indexFile.exists()) {
|
|
|
|
println("Run JS distribution at: ${indexFile.canonicalPath}")
|
2019-07-27 12:48:32 +03:00
|
|
|
}
|
2020-04-07 12:49:40 +03:00
|
|
|
}
|
2020-03-14 14:42:11 +03:00
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
2020-07-05 14:39:35 +03:00
|
|
|
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
|
|
|
}
|
2020-07-05 14:39:35 +03:00
|
|
|
}
|