2019-06-28 16:22:11 +03:00
|
|
|
package scientifik
|
|
|
|
|
|
|
|
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
|
2019-07-24 15:03:12 +03:00
|
|
|
import org.gradle.api.tasks.Copy
|
2019-08-09 11:51:30 +03:00
|
|
|
import org.gradle.api.tasks.bundling.Jar
|
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
|
2019-07-24 15:03:12 +03:00
|
|
|
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
|
2019-07-27 12:48:32 +03:00
|
|
|
import java.io.File
|
2019-06-28 16:22:11 +03:00
|
|
|
|
|
|
|
open class ScientifikMPPlugin : Plugin<Project> {
|
|
|
|
override fun apply(project: Project) {
|
2019-07-20 20:39:26 +03:00
|
|
|
val extension = project.scientifik
|
|
|
|
|
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> {
|
|
|
|
jvm {
|
|
|
|
compilations.all {
|
|
|
|
kotlinOptions {
|
|
|
|
jvmTarget = "1.8"
|
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 11:51:30 +03:00
|
|
|
js {
|
|
|
|
browser {}
|
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
|
2019-07-17 16:04:39 +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"))
|
|
|
|
implementation(kotlin("test-junit"))
|
|
|
|
}
|
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") {
|
|
|
|
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
|
|
|
|
2019-08-09 11:51:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
tasks.apply {
|
|
|
|
val jsBrowserWebpack by getting(KotlinWebpack::class) {
|
|
|
|
archiveClassifier = "js"
|
|
|
|
project.afterEvaluate {
|
|
|
|
val destination = listOf(archiveBaseName, archiveAppendix, archiveVersion, archiveClassifier)
|
|
|
|
.filter { it != null && it.isNotBlank() }
|
|
|
|
.joinToString("-")
|
|
|
|
destinationDirectory = destinationDirectory?.resolve(destination)
|
|
|
|
}
|
|
|
|
archiveFileName = "main.bundle.js"
|
2019-07-17 16:04:39 +03:00
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
|
2019-08-09 11:51:30 +03:00
|
|
|
afterEvaluate {
|
|
|
|
val installJsDist by creating(Copy::class) {
|
|
|
|
group = "distribution"
|
|
|
|
dependsOn(jsBrowserWebpack)
|
|
|
|
from(project.fileTree("src/jsMain/web"))
|
|
|
|
into(jsBrowserWebpack.destinationDirectory!!)
|
|
|
|
doLast {
|
|
|
|
val indexFile = File(jsBrowserWebpack.destinationDirectory!!, "index.html")
|
|
|
|
if (indexFile.exists()) {
|
|
|
|
println("Run JS distribution at: ${indexFile.canonicalPath}")
|
|
|
|
}
|
2019-07-27 12:48:32 +03:00
|
|
|
}
|
|
|
|
}
|
2019-07-24 15:03:12 +03:00
|
|
|
|
2019-08-09 11:51:30 +03:00
|
|
|
findByName("assemble")?.dependsOn(installJsDist)
|
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|