2019-06-28 16:22:11 +03:00
|
|
|
package scientifik
|
|
|
|
|
2019-11-20 10:41:37 +03:00
|
|
|
import Scientifik
|
2019-06-28 16:22:11 +03:00
|
|
|
import org.gradle.api.Plugin
|
|
|
|
import org.gradle.api.Project
|
2019-08-09 11:51:30 +03:00
|
|
|
import org.gradle.api.plugins.JavaBasePlugin
|
|
|
|
import org.gradle.api.publish.PublishingExtension
|
|
|
|
import org.gradle.api.publish.maven.MavenPublication
|
2020-05-04 19:57:27 +03:00
|
|
|
import org.gradle.api.tasks.Copy
|
2019-08-09 11:51:30 +03:00
|
|
|
import org.gradle.api.tasks.bundling.Jar
|
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-08-09 11:51:30 +03:00
|
|
|
import org.jetbrains.dokka.gradle.DokkaTask
|
2019-06-28 16:22:11 +03:00
|
|
|
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
|
|
|
|
|
|
|
open class ScientifikMPPlugin : Plugin<Project> {
|
|
|
|
override fun apply(project: Project) {
|
2019-08-09 11:51:30 +03:00
|
|
|
project.run {
|
2019-06-28 16:22:11 +03:00
|
|
|
|
2019-08-09 11:51:30 +03:00
|
|
|
plugins.apply("org.jetbrains.kotlin.multiplatform")
|
2019-07-17 16:04:39 +03:00
|
|
|
|
2019-08-09 11:51:30 +03:00
|
|
|
repositories.applyRepos()
|
|
|
|
|
|
|
|
configure<KotlinMultiplatformExtension> {
|
2020-03-14 14:42:11 +03:00
|
|
|
|
2019-08-09 11:51:30 +03:00
|
|
|
jvm {
|
|
|
|
compilations.all {
|
|
|
|
kotlinOptions {
|
2019-11-20 10:41:37 +03:00
|
|
|
jvmTarget = Scientifik.JVM_VERSION
|
2019-08-09 11:51:30 +03:00
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-04 19:57:27 +03:00
|
|
|
val js = js {
|
2020-03-14 14:42:11 +03:00
|
|
|
browser {
|
|
|
|
webpackTask {
|
|
|
|
outputFileName = "main.bundle.js"
|
|
|
|
}
|
|
|
|
distribution {
|
|
|
|
directory = project.jsDistDirectory
|
|
|
|
}
|
|
|
|
}
|
2019-08-09 11:51:30 +03:00
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
|
2019-08-09 11:51:30 +03:00
|
|
|
sourceSets.invoke {
|
|
|
|
val commonMain by getting {
|
|
|
|
dependencies {
|
|
|
|
api(kotlin("stdlib"))
|
2019-07-20 20:39:26 +03:00
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
2019-08-09 11:51:30 +03:00
|
|
|
val commonTest by getting {
|
|
|
|
dependencies {
|
|
|
|
implementation(kotlin("test-common"))
|
|
|
|
implementation(kotlin("test-annotations-common"))
|
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
2019-08-09 11:51:30 +03:00
|
|
|
val jvmMain by getting {
|
|
|
|
dependencies {
|
|
|
|
api(kotlin("stdlib-jdk8"))
|
2019-07-21 17:40:08 +03:00
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
2019-08-09 11:51:30 +03:00
|
|
|
val jvmTest by getting {
|
|
|
|
dependencies {
|
|
|
|
implementation(kotlin("test"))
|
2020-04-07 12:49:40 +03:00
|
|
|
// implementation(kotlin("test-junit"))
|
|
|
|
implementation(kotlin("test-junit5"))
|
|
|
|
implementation("org.junit.jupiter:junit-jupiter:5.6.1")
|
2019-08-09 11:51:30 +03:00
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
2019-08-09 11:51:30 +03:00
|
|
|
val jsMain by getting {
|
|
|
|
dependencies {
|
|
|
|
api(kotlin("stdlib-js"))
|
2019-07-21 17:40:08 +03:00
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
2019-08-09 11:51:30 +03:00
|
|
|
val jsTest by getting {
|
|
|
|
dependencies {
|
|
|
|
implementation(kotlin("test-js"))
|
|
|
|
}
|
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
2019-08-09 11:51:30 +03:00
|
|
|
|
|
|
|
targets.all {
|
|
|
|
sourceSets.all {
|
|
|
|
languageSettings.applySettings()
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
|
|
|
}
|
2019-07-24 15:03:12 +03:00
|
|
|
|
2019-08-09 11:51:30 +03:00
|
|
|
pluginManager.withPlugin("org.jetbrains.dokka") {
|
2019-11-17 21:41:23 +03:00
|
|
|
logger.info("Adding dokka functionality to project ${this@run.name}")
|
2019-08-09 11:51:30 +03:00
|
|
|
val dokka by tasks.getting(DokkaTask::class) {
|
|
|
|
outputFormat = "html"
|
|
|
|
outputDirectory = "$buildDir/javadoc"
|
2019-11-01 22:57:53 +03:00
|
|
|
multiplatform {
|
2019-08-09 11:51:30 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val kdocJar by tasks.registering(Jar::class) {
|
|
|
|
group = JavaBasePlugin.DOCUMENTATION_GROUP
|
|
|
|
dependsOn(dokka)
|
|
|
|
archiveClassifier.set("javadoc")
|
|
|
|
from("$buildDir/javadoc")
|
|
|
|
}
|
|
|
|
|
2019-11-01 22:57:53 +03:00
|
|
|
pluginManager.withPlugin("maven-publish") {
|
|
|
|
configure<PublishingExtension> {
|
2019-08-09 11:51:30 +03:00
|
|
|
|
2019-11-01 22:57:53 +03:00
|
|
|
targets.all {
|
|
|
|
val publication = publications.findByName(name) as MavenPublication
|
2019-08-09 11:51:30 +03:00
|
|
|
|
2019-11-01 22:57:53 +03:00
|
|
|
// Patch publications with fake javadoc
|
|
|
|
publication.artifact(kdocJar.get())
|
|
|
|
}
|
2019-08-09 11:51:30 +03:00
|
|
|
}
|
|
|
|
}
|
2019-07-24 15:03:12 +03:00
|
|
|
}
|
2019-07-17 16:04:39 +03:00
|
|
|
|
2020-03-14 14:42:11 +03:00
|
|
|
tasks.apply {
|
2020-05-04 19:57:27 +03:00
|
|
|
val jsProcessResources by getting(Copy::class)
|
|
|
|
jsProcessResources.copyJSResources(configurations["jsRuntimeClasspath"])
|
2019-12-30 17:02:12 +03:00
|
|
|
|
2020-03-14 14:42:11 +03:00
|
|
|
val jsBrowserDistribution by getting {
|
2019-08-09 11:51:30 +03:00
|
|
|
doLast {
|
2020-03-14 14:42:11 +03:00
|
|
|
val indexFile = project.jsDistDirectory.resolve("index.html")
|
2019-08-09 11:51:30 +03:00
|
|
|
if (indexFile.exists()) {
|
|
|
|
println("Run JS distribution at: ${indexFile.canonicalPath}")
|
|
|
|
}
|
2019-07-27 12:48:32 +03:00
|
|
|
}
|
2020-03-14 14:42:11 +03:00
|
|
|
group = "distribution"
|
2019-07-27 12:48:32 +03:00
|
|
|
}
|
2020-05-04 19:57:27 +03:00
|
|
|
|
2020-04-07 12:49:40 +03:00
|
|
|
withType<Test>() {
|
|
|
|
useJUnitPlatform()
|
|
|
|
}
|
2020-03-14 14:42:11 +03:00
|
|
|
}
|
|
|
|
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|