Added distribution task to JS plugins

This commit is contained in:
Alexander Nozik 2019-07-24 15:03:12 +03:00
parent 361cbaec55
commit ebbd33aa75
6 changed files with 142 additions and 76 deletions

View File

@ -9,7 +9,6 @@ open class ScientifikExtension {
var vcs: String? = null var vcs: String? = null
var bintrayRepo: String? = null var bintrayRepo: String? = null
var kdoc: Boolean = true var kdoc: Boolean = true
internal var native = false
var serialization = false var serialization = false
var atomicfu = false var atomicfu = false
var io = false var io = false

View File

@ -3,11 +3,10 @@ package scientifik
import Scientifik import Scientifik
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure import org.gradle.api.tasks.Copy
import org.gradle.kotlin.dsl.get import org.gradle.kotlin.dsl.*
import org.gradle.kotlin.dsl.maven
import org.gradle.kotlin.dsl.repositories
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
open class ScientifikJSPlugin : Plugin<Project> { open class ScientifikJSPlugin : Plugin<Project> {
override fun apply(project: Project) { override fun apply(project: Project) {
@ -19,39 +18,55 @@ open class ScientifikJSPlugin : Plugin<Project> {
plugins.apply("kotlinx-atomicfu") plugins.apply("kotlinx-atomicfu")
repositories { repositories.applyRepos()
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://kotlin.bintray.com/kotlinx")
maven("https://dl.bintray.com/mipt-npm/dev")
}
configure<KotlinJsProjectExtension> { configure<KotlinJsProjectExtension> {
target { target {
browser() browser()
} }
sourceSets["main"].apply { sourceSets["main"].apply {
languageSettings.apply { languageSettings.applySettings()
progressiveMode = true
enableLanguageFeature("InlineClasses")
useExperimentalAnnotation("ExperimentalUnsignedType")
}
dependencies { dependencies {
api(kotlin("stdlib-jdk8")) api(kotlin("stdlib-jdk8"))
if (extension.serialization) { afterEvaluate {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}") if (extension.serialization) {
} implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}")
if (extension.atomicfu) { }
implementation("org.jetbrains.kotlinx:atomicfu-js:${Scientifik.atomicfuVersion}") if (extension.atomicfu) {
} implementation("org.jetbrains.kotlinx:atomicfu-js:${Scientifik.atomicfuVersion}")
if (extension.io) { }
api("org.jetbrains.kotlinx:kotlinx-io-js:${Scientifik.ioVersion}") if (extension.io) {
api("org.jetbrains.kotlinx:kotlinx-io-js:${Scientifik.ioVersion}")
}
} }
} }
} }
} }
tasks.apply {
val browserWebpack by getting(KotlinWebpack::class) {
afterEvaluate {
val destination = listOf(archiveBaseName, archiveAppendix, archiveVersion, archiveClassifier)
.filter { it != null && it.isNotBlank() }
.joinToString("-")
destinationDirectory = destinationDirectory?.resolve(destination)
}
archiveFileName = "main.bundle.js"
}
afterEvaluate {
val installJsDist by creating(Copy::class) {
group = "distribution"
dependsOn(browserWebpack)
from(fileTree("src/main/web"))
into(browserWebpack.destinationDirectory!!)
}
findByName("assemble")?.dependsOn(installJsDist)
}
}
} }
} }

View File

@ -3,7 +3,9 @@ package scientifik
import Scientifik import Scientifik
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@ -16,13 +18,7 @@ open class ScientifikJVMPlugin : Plugin<Project> {
plugins.apply("kotlinx-serialization") plugins.apply("kotlinx-serialization")
plugins.apply("kotlinx-atomicfu") plugins.apply("kotlinx-atomicfu")
repositories { repositories.applyRepos()
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://kotlin.bintray.com/kotlinx")
maven("https://dl.bintray.com/mipt-npm/dev")
}
tasks.withType<KotlinCompile> { tasks.withType<KotlinCompile> {
kotlinOptions { kotlinOptions {
@ -32,22 +28,20 @@ open class ScientifikJVMPlugin : Plugin<Project> {
configure<KotlinJvmProjectExtension> { configure<KotlinJvmProjectExtension> {
sourceSets["main"].apply { sourceSets["main"].apply {
languageSettings.apply { languageSettings.applySettings()
progressiveMode = true
enableLanguageFeature("InlineClasses")
useExperimentalAnnotation("ExperimentalUnsignedType")
}
dependencies { dependencies {
api(kotlin("stdlib-jdk8")) api(kotlin("stdlib-jdk8"))
if (extension.serialization) { afterEvaluate {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}") if (extension.serialization) {
} implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Scientifik.serializationVersion}")
if (extension.atomicfu) { }
implementation("org.jetbrains.kotlinx:atomicfu:${Scientifik.atomicfuVersion}") if (extension.atomicfu) {
} implementation("org.jetbrains.kotlinx:atomicfu:${Scientifik.atomicfuVersion}")
if (extension.io) { }
api("org.jetbrains.kotlinx:kotlinx-io-jvm:${Scientifik.ioVersion}") if (extension.io) {
api("org.jetbrains.kotlinx:kotlinx-io-jvm:${Scientifik.ioVersion}")
}
} }
} }
} }

View File

@ -3,8 +3,10 @@ package scientifik
import Scientifik import Scientifik
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.tasks.Copy
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
open class ScientifikMPPlugin : Plugin<Project> { open class ScientifikMPPlugin : Plugin<Project> {
override fun apply(project: Project) { override fun apply(project: Project) {
@ -14,13 +16,7 @@ open class ScientifikMPPlugin : Plugin<Project> {
project.plugins.apply("kotlinx-serialization") project.plugins.apply("kotlinx-serialization")
project.plugins.apply("kotlinx-atomicfu") project.plugins.apply("kotlinx-atomicfu")
project.repositories { project.repositories.applyRepos()
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://kotlin.bintray.com/kotlinx")
maven("https://dl.bintray.com/mipt-npm/dev")
}
project.configure<KotlinMultiplatformExtension> { project.configure<KotlinMultiplatformExtension> {
jvm { jvm {
@ -35,10 +31,6 @@ open class ScientifikMPPlugin : Plugin<Project> {
browser {} browser {}
} }
if (extension.native) {
linuxX64()
mingwX64()
}
sourceSets.invoke { sourceSets.invoke {
val commonMain by getting { val commonMain by getting {
@ -100,32 +92,38 @@ open class ScientifikMPPlugin : Plugin<Project> {
implementation(kotlin("test-js")) implementation(kotlin("test-js"))
} }
} }
project.afterEvaluate {
if (extension.native) {
val native by creating {
dependsOn(commonMain)
}
mingwX64().compilations["main"].defaultSourceSet {
dependsOn(native)
}
linuxX64().compilations["main"].defaultSourceSet {
dependsOn(native)
}
}
}
} }
targets.all { targets.all {
sourceSets.all { sourceSets.all {
languageSettings.apply { languageSettings.applySettings()
progressiveMode = true
enableLanguageFeature("InlineClasses")
useExperimentalAnnotation("ExperimentalUnsignedType")
}
} }
} }
} }
project.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"
}
project.afterEvaluate {
val installJsDist by creating(Copy::class) {
group = "distribution"
dependsOn(jsBrowserWebpack)
from(project.fileTree("src/jsMain/web"))
into(jsBrowserWebpack.destinationDirectory!!)
}
findByName("assemble")?.dependsOn(installJsDist)
}
}
} }
} }

View File

@ -0,0 +1,40 @@
package scientifik
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
class ScientifikNativePlugin : Plugin<Project> {
override fun apply(target: Project) {
target.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
target.configure<KotlinMultiplatformExtension> {
linuxX64()
mingwX64()
sourceSets.apply {
val commonMain by getting {}
val native by creating {
dependsOn(commonMain)
dependencies {
//TODO add stdlib here
target.afterEvaluate {
//TODO add optional libraries here
}
}
}
mingwX64().compilations["main"].defaultSourceSet {
dependsOn(native)
}
linuxX64().compilations["main"].defaultSourceSet {
dependsOn(native)
}
}
}
}
}
}

View File

@ -0,0 +1,20 @@
package scientifik
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.kotlin.dsl.maven
import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder
internal fun LanguageSettingsBuilder.applySettings(): Unit {
progressiveMode = true
enableLanguageFeature("InlineClasses")
useExperimentalAnnotation("kotlin.ExperimentalUnsignedType")
}
internal fun RepositoryHandler.applyRepos(): Unit{
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://kotlin.bintray.com/kotlinx")
maven("https://dl.bintray.com/mipt-npm/scientifik")
maven("https://dl.bintray.com/mipt-npm/dev")
}