From 9e37d6f7525fc96f56d23fd622f5f3fb39c0e6ce Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 4 May 2020 19:57:27 +0300 Subject: [PATCH] Fix for https://youtrack.jetbrains.com/issue/KT-38230. Breakin change on the API. --- build.gradle.kts | 18 ++-- .../kotlin/scientifik/ScientifikJSPlugin.kt | 4 + .../kotlin/scientifik/ScientifikJVMPlugin.kt | 3 +- .../kotlin/scientifik/ScientifikMPPlugin.kt | 9 +- src/main/kotlin/scientifik/common.kt | 33 +++++++ src/main/kotlin/scientifik/extensions.kt | 87 +----------------- src/main/kotlin/scientifik/fx.kt | 4 +- src/main/kotlin/scientifik/serialization.kt | 89 +++++++++++++++++++ 8 files changed, 144 insertions(+), 103 deletions(-) create mode 100644 src/main/kotlin/scientifik/serialization.kt diff --git a/build.gradle.kts b/build.gradle.kts index deaded4..36a6d46 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,11 +3,11 @@ import java.util.* plugins { `kotlin-dsl` `maven-publish` - id("com.jfrog.bintray") version "1.8.4" + id("com.jfrog.bintray") version "1.8.5" } group = "scientifik" -version = "0.4.2" +version = "0.5.0" repositories { gradlePluginPortal() @@ -16,7 +16,7 @@ repositories { maven("https://dl.bintray.com/kotlin/kotlin-eap") } -val kotlinVersion = "1.3.71" +val kotlinVersion = "1.3.72" java { targetCompatibility = JavaVersion.VERSION_1_8 @@ -26,7 +26,7 @@ java { dependencies { implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") implementation("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion") - implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.14.2") + implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.14.3") implementation("org.jetbrains.dokka:dokka-gradle-plugin:0.10.1") } @@ -56,11 +56,11 @@ gradlePlugin { implementationClass = "scientifik.ScientifikJSPlugin" } - create("scientifik-atomic") { - id = "scientifik.atomic" - description = "Add kotlin atomic plugin to any flafor" - implementationClass = "scientifik.ScientifikAtomicPlugin" - } +// create("scientifik-atomic") { +// id = "scientifik.atomic" +// description = "Add kotlin atomic plugin to any flafor" +// implementationClass = "scientifik.ScientifikAtomicPlugin" +// } } } diff --git a/src/main/kotlin/scientifik/ScientifikJSPlugin.kt b/src/main/kotlin/scientifik/ScientifikJSPlugin.kt index 164b37f..f567422 100644 --- a/src/main/kotlin/scientifik/ScientifikJSPlugin.kt +++ b/src/main/kotlin/scientifik/ScientifikJSPlugin.kt @@ -2,6 +2,7 @@ package scientifik import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.tasks.Copy import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.get import org.gradle.kotlin.dsl.getValue @@ -45,6 +46,9 @@ open class ScientifikJSPlugin : Plugin { tasks.apply { + val processResources by getting(Copy::class) + processResources.copyJSResources(configurations["runtimeClasspath"]) + val browserDistribution by getting { doLast { val indexFile = project.jsDistDirectory.resolve("index.html") diff --git a/src/main/kotlin/scientifik/ScientifikJVMPlugin.kt b/src/main/kotlin/scientifik/ScientifikJVMPlugin.kt index c134df0..cbcd037 100644 --- a/src/main/kotlin/scientifik/ScientifikJVMPlugin.kt +++ b/src/main/kotlin/scientifik/ScientifikJVMPlugin.kt @@ -1,7 +1,6 @@ package scientifik import Scientifik -import org.gradle.api.JavaVersion import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.plugins.JavaBasePlugin @@ -23,7 +22,7 @@ open class ScientifikJVMPlugin : Plugin { repositories.applyRepos() extensions.findByType()?.apply { - targetCompatibility = JavaVersion.VERSION_11 + targetCompatibility = enumValueOf(Scientifik.JVM_VERSION) } tasks.withType { diff --git a/src/main/kotlin/scientifik/ScientifikMPPlugin.kt b/src/main/kotlin/scientifik/ScientifikMPPlugin.kt index 5d4da2e..720fe76 100644 --- a/src/main/kotlin/scientifik/ScientifikMPPlugin.kt +++ b/src/main/kotlin/scientifik/ScientifikMPPlugin.kt @@ -6,6 +6,7 @@ import org.gradle.api.Project import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.tasks.Copy import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.testing.Test import org.gradle.kotlin.dsl.* @@ -30,7 +31,7 @@ open class ScientifikMPPlugin : Plugin { } } - js { + val js = js { browser { webpackTask { outputFileName = "main.bundle.js" @@ -114,10 +115,9 @@ open class ScientifikMPPlugin : Plugin { } } - - - tasks.apply { + val jsProcessResources by getting(Copy::class) + jsProcessResources.copyJSResources(configurations["jsRuntimeClasspath"]) val jsBrowserDistribution by getting { doLast { @@ -128,6 +128,7 @@ open class ScientifikMPPlugin : Plugin { } group = "distribution" } + withType() { useJUnitPlatform() } diff --git a/src/main/kotlin/scientifik/common.kt b/src/main/kotlin/scientifik/common.kt index 0f7738e..f917810 100644 --- a/src/main/kotlin/scientifik/common.kt +++ b/src/main/kotlin/scientifik/common.kt @@ -1,7 +1,10 @@ package scientifik import org.gradle.api.Project +import org.gradle.api.artifacts.Configuration +import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.artifacts.dsl.RepositoryHandler +import org.gradle.api.tasks.Copy import org.gradle.kotlin.dsl.maven import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder import java.io.File @@ -26,6 +29,36 @@ internal fun RepositoryHandler.applyRepos(): Unit { maven("https://dl.bintray.com/mipt-npm/dataforge") } + +internal fun Copy.copyJSResources(configuration: Configuration): Unit = project.afterEvaluate { + val projectDeps = configuration + .allDependencies + .filterIsInstance() + .map { it.dependencyProject } + + val destination = destinationDir + + projectDeps.forEach { dep -> + dep.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { + dep.tasks.findByName("jsProcessResources")?.let { task -> + val sourceDir = (task as Copy).destinationDir + inputs.files(sourceDir) + dependsOn(task) + from(sourceDir) + } + } + dep.pluginManager.withPlugin("org.jetbrains.kotlin.js") { + dep.tasks.findByName("processResources")?.let { task -> + val sourceDir = (task as Copy).destinationDir + inputs.files(sourceDir) + dependsOn(task) + from(sourceDir) + } + } + } +} + + val Project.jsDistDirectory: File get() { val distributionName = listOf( diff --git a/src/main/kotlin/scientifik/extensions.kt b/src/main/kotlin/scientifik/extensions.kt index df52b26..d349c5c 100644 --- a/src/main/kotlin/scientifik/extensions.kt +++ b/src/main/kotlin/scientifik/extensions.kt @@ -5,8 +5,6 @@ import kotlinx.atomicfu.plugin.gradle.sourceSets import org.gradle.api.Project import org.gradle.kotlin.dsl.findByType import org.gradle.kotlin.dsl.invoke -import org.gradle.kotlin.dsl.maven -import org.gradle.kotlin.dsl.repositories import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension enum class DependencyConfiguration { @@ -75,90 +73,7 @@ internal fun Project.useDependency( } } -class SerializationTargets( - val sourceSet: DependencySourceSet, - val configuration: DependencyConfiguration -) { - fun Project.cbor( - version: String = Scientifik.serializationVersion - ) { - useDependency( - "common" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor-common:$version", - "jvm" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor:$version", - "js" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor-js:$version", - "native" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor-native:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } - - fun Project.protobuf( - version: String = Scientifik.serializationVersion - ) { - useDependency( - "common" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf-common:$version", - "jvm" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$version", - "js" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf-js:$version", - "native" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf-native:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } - - fun Project.xml( - version: String = Scientifik.Serialization.xmlVersion - ) { - repositories { - maven("https://dl.bintray.com/pdvrieze/maven") - } - useDependency( - "common" to "net.devrieze:xmlutil-serialization:$version", - "jvm" to "net.devrieze:xmlutil-serialization:$version", - "js" to "net.devrieze:xmlutil-serialization:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } - - fun Project.yaml( - version: String = Scientifik.Serialization.yamlVersion - ) { - useDependency( - "jvm" to "com.charleskorn.kaml:kaml:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } - - fun Project.bson( - version: String = Scientifik.Serialization.bsonVersion - ) { - useDependency( - "jvm" to "com.github.jershell:kbson:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } -} - -fun Project.serialization( - version: String = Scientifik.serializationVersion, - sourceSet: DependencySourceSet = DependencySourceSet.MAIN, - configuration: DependencyConfiguration = DependencyConfiguration.API, - block: SerializationTargets.() -> Unit = {} -) { - plugins.apply("org.jetbrains.kotlin.plugin.serialization") - useDependency( - "common" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$version", - "jvm" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$version", - "js" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$version", - "native" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$version", - dependencySourceSet = sourceSet - ) - SerializationTargets(sourceSet, configuration).apply(block) -} - -fun Project.coroutines( +fun Project.useCoroutines( version: String = Scientifik.coroutinesVersion, sourceSet: DependencySourceSet = DependencySourceSet.MAIN, configuration: DependencyConfiguration = DependencyConfiguration.API diff --git a/src/main/kotlin/scientifik/fx.kt b/src/main/kotlin/scientifik/fx.kt index f284d23..d86b888 100644 --- a/src/main/kotlin/scientifik/fx.kt +++ b/src/main/kotlin/scientifik/fx.kt @@ -46,12 +46,12 @@ fun KotlinDependencyHandler.addFXDependencies( } } -fun Project.fx( +fun Project.useFx( vararg modules: FXModule, configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY, version: String = "14", platform: FXPlatform = defaultPlatform -) { +): Unit = afterEvaluate{ pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { extensions.findByType()?.apply { sourceSets.findByName("jvmMain")?.apply { diff --git a/src/main/kotlin/scientifik/serialization.kt b/src/main/kotlin/scientifik/serialization.kt new file mode 100644 index 0000000..2121f69 --- /dev/null +++ b/src/main/kotlin/scientifik/serialization.kt @@ -0,0 +1,89 @@ +package scientifik + +import Scientifik +import org.gradle.api.Project +import org.gradle.kotlin.dsl.maven +import org.gradle.kotlin.dsl.repositories + +class SerializationTargets( + val sourceSet: DependencySourceSet, + val configuration: DependencyConfiguration +) { + fun Project.cbor( + version: String = Scientifik.serializationVersion + ) { + useDependency( + "common" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor-common:$version", + "jvm" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor:$version", + "js" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor-js:$version", + "native" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor-native:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration + ) + } + + fun Project.protobuf( + version: String = Scientifik.serializationVersion + ) { + useDependency( + "common" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf-common:$version", + "jvm" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$version", + "js" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf-js:$version", + "native" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf-native:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration + ) + } + + fun Project.xml( + version: String = Scientifik.Serialization.xmlVersion + ) { + repositories { + maven("https://dl.bintray.com/pdvrieze/maven") + } + useDependency( + "common" to "net.devrieze:xmlutil-serialization:$version", + "jvm" to "net.devrieze:xmlutil-serialization:$version", + "js" to "net.devrieze:xmlutil-serialization:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration + ) + } + + fun Project.yaml( + version: String = Scientifik.Serialization.yamlVersion + ) { + useDependency( + "jvm" to "com.charleskorn.kaml:kaml:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration + ) + } + + fun Project.bson( + version: String = Scientifik.Serialization.bsonVersion + ) { + useDependency( + "jvm" to "com.github.jershell:kbson:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration + ) + } +} + +fun Project.useSerialization( + version: String = Scientifik.serializationVersion, + sourceSet: DependencySourceSet = DependencySourceSet.MAIN, + configuration: DependencyConfiguration = DependencyConfiguration.API, + block: SerializationTargets.() -> Unit = {} +) { + plugins.apply("org.jetbrains.kotlin.plugin.serialization") + useDependency( + "common" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$version", + "jvm" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$version", + "js" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$version", + "native" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$version", + dependencySourceSet = sourceSet + ) + SerializationTargets(sourceSet, configuration).apply(block) +} \ No newline at end of file