107 lines
3.4 KiB
Kotlin
Raw Normal View History

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
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.*
import org.jetbrains.dokka.gradle.DokkaTask
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 {
2019-06-28 16:22:11 +03:00
2020-07-05 14:39:35 +03:00
plugins.apply("org.jetbrains.kotlin.multiplatform")
2020-08-20 10:02:28 +03:00
val extension = extensions.add("kscience", KScienceExtension(this))
2019-07-17 16:04:39 +03:00
2020-07-05 14:39:35 +03:00
repositories.applyRepos()
2020-07-05 14:39:35 +03:00
configure<KotlinMultiplatformExtension> {
2020-08-20 10:02:28 +03:00
explicitApiWarning()
2020-07-05 14:39:35 +03:00
jvm {
compilations.all {
kotlinOptions {
2020-08-20 10:02:28 +03:00
useIR = true
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-07-05 14:39:35 +03:00
browser {
webpackTask {
outputFileName = "main.bundle.js"
}
distribution {
directory = project.jsDistDirectory
}
}
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-06-28 16:22:11 +03:00
}
2020-07-05 14:39:35 +03:00
}
2020-07-05 14:39:35 +03:00
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-07-05 14:39:35 +03:00
pluginManager.withPlugin("org.jetbrains.dokka") {
logger.info("Adding dokka functionality to project ${this@run.name}")
2020-08-20 10:02:28 +03:00
val dokkaHtml by tasks.getting(DokkaTask::class) {
dokkaSourceSets {
configureEach {
jdkVersion = 11
}
}
2019-07-24 15:03:12 +03:00
}
2020-07-05 14:39:35 +03:00
}
2019-07-17 16:04:39 +03:00
2020-07-05 14:39:35 +03:00
tasks.apply {
2020-07-06 09:52:54 +03:00
withType<Test>() {
useJUnitPlatform()
}
2020-07-05 14:39:35 +03:00
val jsProcessResources by getting(Copy::class)
jsProcessResources.copyJSResources(configurations["jsRuntimeClasspath"])
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}")
}
2020-04-07 12:49:40 +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
}