From b4fb5c515a5cf4fba7ef3473e5c12cddea3cd470 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 3 Feb 2023 13:00:11 +0300 Subject: [PATCH] Move to manual target configuration --- CHANGELOG.md | 3 + build.gradle.kts | 18 +- gradle/libs.versions.toml | 16 +- .../kscience/gradle/KScienceExtension.kt | 171 +++++++++-------- .../space/kscience/gradle/KScienceJSPlugin.kt | 43 ++++- .../kscience/gradle/KScienceJVMPlugin.kt | 47 ++++- .../space/kscience/gradle/KScienceMPPlugin.kt | 38 +++- .../gradle/KScienceReadmeExtension.kt | 5 - .../space/kscience/gradle/KScienceVersions.kt | 4 +- .../kscience/gradle/commonConfigurations.kt | 175 ------------------ .../space/kscience/gradle/internal/common.kt | 66 ++----- .../space/kscience/gradle/internal/fx.kt | 61 ------ 12 files changed, 255 insertions(+), 392 deletions(-) delete mode 100644 src/main/kotlin/space/kscience/gradle/commonConfigurations.kt delete mode 100644 src/main/kotlin/space/kscience/gradle/internal/fx.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index c18235d..88fcf47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed +- MPP does not use JVM and JS(IR) targets anymore. They could be turned manually via `js()`, `jvm()` or `fullStack()` ### Deprecated ### Removed +- FX plugins +- Unnecessary library shortcuts (html and datetime) ### Fixed diff --git a/build.gradle.kts b/build.gradle.kts index f22cdf4..d1b3259 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,11 +1,11 @@ plugins { - alias(libs.plugins.changelog) - alias(libs.plugins.dokka) `java-gradle-plugin` `kotlin-dsl` `maven-publish` signing `version-catalog` + alias(libs.plugins.changelog) + alias(libs.plugins.dokka) } group = "space.kscience" @@ -21,8 +21,6 @@ repositories { maven("https://repo.kotlin.link") } -java.targetCompatibility = JavaVersion.VERSION_11 - kotlin.explicitApiWarning() dependencies { @@ -33,7 +31,7 @@ dependencies { implementation(libs.kotlin.jupyter.gradle) implementation(libs.kotlin.serialization) implementation(libs.kotlinx.html) - implementation("org.tomlj:tomlj:1.0.0") + implementation("org.tomlj:tomlj:1.1.0") // // nexus publishing plugin // implementation("io.github.gradle-nexus:publish-plugin:1.1.0") @@ -156,8 +154,8 @@ afterEvaluate { } val spaceRepo = "https://maven.pkg.jetbrains.space/spc/p/sci/maven" - val spaceUser: String? = project.findProperty("publishing.space.user") as? String - val spaceToken: String? = project.findProperty("publishing.space.token") as? String + val spaceUser: String? = findProperty("publishing.space.user") as? String + val spaceToken: String? = findProperty("publishing.space.token") as? String if (spaceUser != null && spaceToken != null) { project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]") @@ -205,8 +203,10 @@ afterEvaluate { } } -tasks.withType { - kotlinOptions.jvmTarget = "11" +kotlin{ + jvmToolchain{ + languageVersion.set(JavaLanguageVersion.of(11)) + } } tasks.processResources.configure { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b951e61..e76174a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,11 +1,11 @@ [versions] -tools = "0.13.4-kotlin-1.8.0" +tools = "0.14.0-kotlin-1.8.0" kotlin = "1.8.0" -atomicfu = "0.18.5" +atomicfu = "0.19.0" binary-compatibility-validator = "0.12.1" changelog = "2.0.0" dokka = "1.7.20" -kotlin-jupyter = "0.11.0-216" +kotlin-jupyter = "0.11.0-225" kotlinx-benchmark = "0.4.7" kotlinx-cli = "0.3.5" kotlinx-coroutines = "1.6.4" @@ -13,12 +13,13 @@ kotlinx-datetime = "0.4.0" kotlinx-html = "0.8.0" kotlinx-knit = "0.4.0" kotlinx-nodejs = "0.0.7" -kotlinx-serialization = "1.4.1" -ktor = "2.2.1" +kotlinx-serialization = "1.5.0-RC" +ktor = "2.2.3" xmlutil = "0.84.3" yamlkt = "0.12.0" -jsBom = "1.0.0-pre.466" -junit = "5.8.2" +jsBom = "1.0.0-pre.491" +junit = "5.9.2" +compose = "1.3.0" [libraries] atomicfu-gradle = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "atomicfu" } @@ -81,6 +82,7 @@ yamlkt = { module = "net.mamoe.yamlkt:yamlkt", version.ref = "yamlkt" } changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" } dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } +compose = {id = "org.jetbrains.compose", version.ref = "compose"} gradle-common = { id = "space.kscience.gradle.common", version.ref = "tools" } gradle-project = { id = "space.kscience.gradle.project", version.ref = "tools" } diff --git a/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt b/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt index 4fe3f70..a4b332e 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt @@ -1,37 +1,26 @@ package space.kscience.gradle import org.gradle.api.Project +import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.plugins.ApplicationPlugin +import org.gradle.api.tasks.Copy +import org.gradle.api.tasks.testing.Test import org.gradle.kotlin.dsl.* +import org.gradle.language.jvm.tasks.ProcessResources import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBrowserDsl import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlinx.jupyter.api.plugin.tasks.JupyterApiResourcesTask -import space.kscience.gradle.internal.defaultPlatform +import space.kscience.gradle.internal.defaultKotlinJvmArgs +import space.kscience.gradle.internal.fromJsDependencies import space.kscience.gradle.internal.useCommonDependency -import space.kscience.gradle.internal.useFx - -public enum class FXModule(public val artifact: String, public vararg val dependencies: FXModule) { - BASE("javafx-base"), - GRAPHICS("javafx-graphics", BASE), - CONTROLS("javafx-controls", GRAPHICS, BASE), - FXML("javafx-fxml", BASE), - MEDIA("javafx-media", GRAPHICS, BASE), - SWING("javafx-swing", GRAPHICS, BASE), - WEB("javafx-web", CONTROLS, GRAPHICS, BASE) -} - -public enum class FXPlatform(public val id: String) { - WINDOWS("win"), - LINUX("linux"), - MAC("mac") -} public enum class DependencyConfiguration { API, @@ -45,6 +34,15 @@ public enum class DependencySourceSet(public val setName: String, public val suf } +/** + * Check if this project version has a development tag (`development` property to true, "dev" in the middle or "SNAPSHOT" in the end). + */ +public val Project.isInDevelopment: Boolean + get() = findProperty("development") == true + || "dev" in version.toString() + || version.toString().endsWith("SNAPSHOT") + + public open class KScienceExtension(public val project: Project) { /** @@ -90,43 +88,6 @@ public open class KScienceExtension(public val project: Project) { SerializationTargets(sourceSet, configuration).block() } - /** - * Add platform-specific JavaFX dependencies with given list of [FXModule]s - */ - @Deprecated("Use manual FX configuration") - public fun useFx( - vararg modules: FXModule, - configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY, - version: String = "11", - platform: FXPlatform = defaultPlatform, - ): Unit = project.useFx(modules.toList(), configuration, version, platform) - - /** - * Add dependency on kotlinx-html library - */ - public fun useHtml( - version: String = KScienceVersions.htmlVersion, - sourceSet: DependencySourceSet = DependencySourceSet.MAIN, - configuration: DependencyConfiguration = DependencyConfiguration.API, - ): Unit = project.useCommonDependency( - "org.jetbrains.kotlinx:kotlinx-html:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - - /** - * Use kotlinx-datetime library with default version or [version] - */ - public fun useDateTime( - version: String = KScienceVersions.dateTimeVersion, - sourceSet: DependencySourceSet = DependencySourceSet.MAIN, - configuration: DependencyConfiguration = DependencyConfiguration.API, - ): Unit = project.useCommonDependency( - "org.jetbrains.kotlinx:kotlinx-datetime:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - /** * Apply jupyter plugin and add entry point for the jupyter library. * If left empty applies a plugin without declaring library producers @@ -138,7 +99,9 @@ public open class KScienceExtension(public val project: Project) { } } - + /** + * Apply common dependencies for different kind of targets + */ public fun dependencies(sourceSet: String? = null, dependencyBlock: KotlinDependencyHandler.() -> Unit) { project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { project.configure { @@ -268,49 +231,105 @@ public class KScienceNativeConfiguration { public open class KScienceMppExtension(project: Project) : KScienceExtension(project) { /** - * Custom configuration for JVM target. If null - disable JVM target + * Enable jvm target */ public fun jvm(block: KotlinJvmTarget.() -> Unit) { project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { project.configure { - jvm(block) + jvm { + compilations.all { + kotlinOptions { + freeCompilerArgs = freeCompilerArgs + defaultKotlinJvmArgs + } + } + block() + } + sourceSets { + getByName("jvmMain") { + dependencies { + implementation(kotlin("test-junit5")) + implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}") + } + } + getByName("jvmTest") { + dependencies { + implementation(kotlin("test-js")) + } + } + } + jvmToolchain { + languageVersion.set(KScienceVersions.JVM_TARGET) + } + } + project.tasks.withType { + useJUnitPlatform() } } } /** - * Remove Jvm target - */ - public fun noJvm() { - project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { - project.configure { - targets.removeIf { it is KotlinJvmTarget } - } - } - } - - /** - * Custom configuration for JS target. If null - disable JS target + * Enable JS-IR (browser) target. */ public fun js(block: KotlinJsTargetDsl.() -> Unit) { project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { project.configure { - js(block) + js(IR) { + browser() + block() + } + } + (project.tasks.findByName("jsProcessResources") as? Copy)?.apply { + fromJsDependencies("jsRuntimeClasspath") } } } - public fun noJs() { - project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { - project.configure { - targets.removeIf { it is KotlinJsTargetDsl } + public fun jvmAndJs() { + jvm {} + js {} + } + + /** + * Jvm and Js source sets including copy of Js bundle into JVM resources + */ + public fun fullStack( + bundleName: String = "js/bundle.js", + jvmConfig: KotlinJvmTarget.() -> Unit = {}, + jsConfig: KotlinJsTargetDsl.() -> Unit = {}, + browserConfig: KotlinJsBrowserDsl.() -> Unit = {}, + ) { + js { + binaries.executable() + browser { + webpackTask { + outputFileName = bundleName + } + browserConfig() } + jsConfig() + } + jvm { + val processResourcesTaskName = + compilations[org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.MAIN_COMPILATION_NAME] + .processResourcesTaskName + + val jsBrowserDistribution = project.tasks.getByName("jsBrowserDistribution") + + project.tasks.getByName(processResourcesTaskName) { + duplicatesStrategy = DuplicatesStrategy.WARN + dependsOn(jsBrowserDistribution) + from(jsBrowserDistribution) + } + jvmConfig() } } + /** + * Enable all supported native targets + */ public fun native(block: KScienceNativeConfiguration.() -> Unit = {}): Unit = with(project) { val nativeConfiguration = KScienceNativeConfiguration().apply(block) - pluginManager.withPlugin("space.kscience.gradle.mpp") { + pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { configure { sourceSets { val nativeTargets: List = diff --git a/src/main/kotlin/space/kscience/gradle/KScienceJSPlugin.kt b/src/main/kotlin/space/kscience/gradle/KScienceJSPlugin.kt index ee7960c..0610cd3 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceJSPlugin.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceJSPlugin.kt @@ -2,6 +2,14 @@ package space.kscience.gradle import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.tasks.Copy +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.get +import org.jetbrains.dokka.gradle.DokkaPlugin +import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension +import space.kscience.gradle.internal.applySettings +import space.kscience.gradle.internal.fromJsDependencies public open class KScienceJSPlugin : Plugin { override fun apply(project: Project): Unit = project.run { @@ -10,6 +18,39 @@ public open class KScienceJSPlugin : Plugin { } else { logger.info("Kotlin JS plugin is already present") } - project.configureKScience() + registerKScienceExtension(::KScienceExtension) + + //logger.info("Applying KScience configuration for JS project") + configure { + js(IR) { browser { } } + + sourceSets.all { + languageSettings.applySettings() + } + + sourceSets["main"].apply { + dependencies { + api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}")) + } + } + + sourceSets["test"].apply { + dependencies { + implementation(kotlin("test-js")) + } + } + + if (explicitApi == null) explicitApiWarning() + } + + (tasks.findByName("processResources") as? Copy)?.apply { + fromJsDependencies("runtimeClasspath") + } + + + // apply dokka for all projects + if (!plugins.hasPlugin("org.jetbrains.dokka")) { + apply() + } } } diff --git a/src/main/kotlin/space/kscience/gradle/KScienceJVMPlugin.kt b/src/main/kotlin/space/kscience/gradle/KScienceJVMPlugin.kt index 749d24a..063685a 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceJVMPlugin.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceJVMPlugin.kt @@ -2,6 +2,16 @@ package space.kscience.gradle import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.tasks.testing.Test +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.get +import org.gradle.kotlin.dsl.withType +import org.jetbrains.dokka.gradle.DokkaPlugin +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import space.kscience.gradle.internal.applySettings +import space.kscience.gradle.internal.defaultKotlinJvmArgs public open class KScienceJVMPlugin : Plugin { override fun apply(project: Project): Unit = project.run { @@ -10,6 +20,41 @@ public open class KScienceJVMPlugin : Plugin { } else { logger.info("Kotlin JVM plugin is already present") } - project.configureKScience() + registerKScienceExtension(::KScienceExtension) + + //logger.info("Applying KScience configuration for JVM project") + configure { + sourceSets.all { + languageSettings.applySettings() + } + + sourceSets["test"].apply { + dependencies { + implementation(kotlin("test-junit5")) + implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}") + } + } + + if (explicitApi == null) explicitApiWarning() + jvmToolchain { + languageVersion.set(KScienceVersions.JVM_TARGET) + } + } + + tasks.withType { + kotlinOptions { + freeCompilerArgs = freeCompilerArgs + defaultKotlinJvmArgs + } + } + + tasks.withType { + useJUnitPlatform() + } + + // apply dokka for all projects + if (!plugins.hasPlugin("org.jetbrains.dokka")) { + apply() + } } + } diff --git a/src/main/kotlin/space/kscience/gradle/KScienceMPPlugin.kt b/src/main/kotlin/space/kscience/gradle/KScienceMPPlugin.kt index 65c53c0..cb02302 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceMPPlugin.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceMPPlugin.kt @@ -2,8 +2,14 @@ package space.kscience.gradle import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.hasPlugin +import org.gradle.kotlin.dsl.invoke +import org.jetbrains.dokka.gradle.DokkaPlugin +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin +import space.kscience.gradle.internal.applySettings public open class KScienceMPPlugin : Plugin { override fun apply(project: Project): Unit = project.run { @@ -13,6 +19,36 @@ public open class KScienceMPPlugin : Plugin { } else { logger.info("Kotlin MPP plugin is already present") } - project.configureKScience() + + registerKScienceExtension(::KScienceMppExtension) + + configure { + + sourceSets { + getByName("commonMain"){ + dependencies { + api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}")) + } + } + getByName("commonTest"){ + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + } + } + } + + sourceSets.all { + languageSettings.applySettings() + } + + if (explicitApi == null) explicitApiWarning() + } + + + // apply dokka for all projects + if (!plugins.hasPlugin("org.jetbrains.dokka")) { + apply() + } } } diff --git a/src/main/kotlin/space/kscience/gradle/KScienceReadmeExtension.kt b/src/main/kotlin/space/kscience/gradle/KScienceReadmeExtension.kt index eec7597..b79e64f 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceReadmeExtension.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceReadmeExtension.kt @@ -90,11 +90,6 @@ public class KScienceReadmeExtension(public val project: Project) { public val features: MutableList = ArrayList() - @Deprecated("Use lambda builder instead.") - public fun feature(id: String, description: String, ref: String? = null, name: String = id) { - features += Feature(id, description, ref, name) - } - public fun feature(id: String, ref: String? = null, name: String = id, description: () -> String) { features += Feature(id, description(), ref, name) } diff --git a/src/main/kotlin/space/kscience/gradle/KScienceVersions.kt b/src/main/kotlin/space/kscience/gradle/KScienceVersions.kt index d76fe3d..a70d28f 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceVersions.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceVersions.kt @@ -1,7 +1,7 @@ package space.kscience.gradle -import org.gradle.api.JavaVersion +import org.gradle.jvm.toolchain.JavaLanguageVersion import org.tomlj.Toml /** @@ -24,7 +24,7 @@ public object KScienceVersions { public val jsBom: String get() = toml.getString("versions.jsBom")!! internal val junit: String get() = toml.getString("versions.junit")!! - public val JVM_TARGET: JavaVersion = JavaVersion.VERSION_11 + public val JVM_TARGET: JavaLanguageVersion = JavaLanguageVersion.of(11) public object Serialization { public val xmlVersion: String get() = toml.getString("versions.xmlutil")!! diff --git a/src/main/kotlin/space/kscience/gradle/commonConfigurations.kt b/src/main/kotlin/space/kscience/gradle/commonConfigurations.kt deleted file mode 100644 index 37aa7e3..0000000 --- a/src/main/kotlin/space/kscience/gradle/commonConfigurations.kt +++ /dev/null @@ -1,175 +0,0 @@ -package space.kscience.gradle - -import org.gradle.api.Project -import org.gradle.api.plugins.JavaPluginExtension -import org.gradle.api.tasks.Copy -import org.gradle.api.tasks.testing.Test -import org.gradle.kotlin.dsl.* -import org.jetbrains.dokka.gradle.DokkaPlugin -import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import space.kscience.gradle.internal.applyRepos -import space.kscience.gradle.internal.applySettings -import space.kscience.gradle.internal.fromJsDependencies - - -private val defaultKotlinJvmArgs: List = - listOf("-Xjvm-default=all", "-Xlambdas=indy"/* "-Xjdk-release=${KScienceVersions.JVM_TARGET}"*/) - -private fun resolveKotlinVersion(): KotlinVersion { - val (major, minor, patch) = KScienceVersions.kotlinVersion.split(".", "-") - return KotlinVersion(major.toInt(), minor.toInt(), patch.toInt()) -} - - -/** - * Check if this project version has a development tag (`development` property to true, "dev" in the middle or "SNAPSHOT" in the end). - */ -public val Project.isInDevelopment: Boolean - get() = findProperty("development") == true - || "dev" in version.toString() - || version.toString().endsWith("SNAPSHOT") - -/** - * Configure KScience extensions - */ -@Suppress("UNUSED_VARIABLE") -public fun Project.configureKScience( - kotlinVersion: KotlinVersion = resolveKotlinVersion(), -) { - repositories.applyRepos() - - //Configuration for K-JVM plugin - pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { - val extension = registerKScienceExtension(::KScienceExtension) - - //logger.info("Applying KScience configuration for JVM project") - configure { - sourceSets.all { - languageSettings.applySettings(kotlinVersion) - } - - sourceSets["test"].apply { - dependencies { - implementation(kotlin("test-junit5")) - implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}") - } - } - - if (explicitApi == null) explicitApiWarning() - } - tasks.withType { - kotlinOptions { - jvmTarget = KScienceVersions.JVM_TARGET.toString() - freeCompilerArgs = freeCompilerArgs + defaultKotlinJvmArgs - } - } - - extensions.findByType()?.apply { - targetCompatibility = KScienceVersions.JVM_TARGET - } - - tasks.withType { - useJUnitPlatform() - } - } - - pluginManager.withPlugin("org.jetbrains.kotlin.js") { - val extension = registerKScienceExtension(::KScienceExtension) - - //logger.info("Applying KScience configuration for JS project") - configure { - js(IR) { browser { } } - - sourceSets.all { - languageSettings.applySettings(kotlinVersion) - } - - sourceSets["main"].apply { - dependencies { - api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}")) - } - } - - sourceSets["test"].apply { - dependencies { - implementation(kotlin("test-js")) - } - } - - if (explicitApi == null) explicitApiWarning() - } - - (tasks.findByName("processResources") as? Copy)?.apply { - fromJsDependencies("runtimeClasspath") - } - - } - - pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { - val extension = registerKScienceExtension(::KScienceMppExtension) - - configure { - jvm { - compilations.all { - kotlinOptions { - jvmTarget = KScienceVersions.JVM_TARGET.toString() - freeCompilerArgs = freeCompilerArgs + defaultKotlinJvmArgs - } - } - } - - js(IR) { browser { } } - - sourceSets { - val commonMain by getting { - dependencies { - api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}")) - } - } - val commonTest by getting { - dependencies { - implementation(kotlin("test-common")) - implementation(kotlin("test-annotations-common")) - } - } - val jvmTest by getting { - dependencies { - implementation(kotlin("test-junit5")) - implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}") - } - } - val jsTest by getting { - dependencies { - implementation(kotlin("test-js")) - } - } - } - - sourceSets.all { - languageSettings.applySettings(kotlinVersion) - } - - (tasks.findByName("jsProcessResources") as? Copy)?.apply { - fromJsDependencies("jsRuntimeClasspath") - } - - extensions.findByType()?.apply { - targetCompatibility = KScienceVersions.JVM_TARGET - } - - tasks.withType { - useJUnitPlatform() - } - - if (explicitApi == null) explicitApiWarning() - } - } - - // apply dokka for all projects - if (!plugins.hasPlugin("org.jetbrains.dokka")) { - apply() - } -} \ No newline at end of file diff --git a/src/main/kotlin/space/kscience/gradle/internal/common.kt b/src/main/kotlin/space/kscience/gradle/internal/common.kt index 718fb15..f1f2df4 100644 --- a/src/main/kotlin/space/kscience/gradle/internal/common.kt +++ b/src/main/kotlin/space/kscience/gradle/internal/common.kt @@ -2,17 +2,23 @@ package space.kscience.gradle.internal import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.artifacts.dsl.RepositoryHandler -import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.tasks.Copy import org.gradle.kotlin.dsl.get -import org.gradle.kotlin.dsl.getByName import org.gradle.kotlin.dsl.maven -import org.gradle.language.jvm.tasks.ProcessResources -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder +import space.kscience.gradle.KScienceVersions + + +internal val defaultKotlinJvmArgs: List = + listOf("-Xjvm-default=all", "-Xlambdas=indy"/* "-Xjdk-release=${KScienceVersions.JVM_TARGET}"*/) + +internal fun resolveKotlinVersion(): KotlinVersion { + val (major, minor, patch) = KScienceVersions.kotlinVersion.split(".", "-") + return KotlinVersion(major.toInt(), minor.toInt(), patch.toInt()) +} internal fun LanguageSettingsBuilder.applySettings( - kotlinVersion: KotlinVersion + kotlinVersion: KotlinVersion = resolveKotlinVersion(), ) { val versionString = "${kotlinVersion.major}.${kotlinVersion.minor}" languageVersion = versionString @@ -52,52 +58,4 @@ internal fun Copy.fromJsDependencies(configurationName: String) = project.run { } } } -} - -internal fun KotlinMultiplatformExtension.bundleJsBinaryAsResource(bundleName: String = "js/bundle.js") { - js(IR) { - binaries.executable() - browser { - webpackTask { - outputFileName = bundleName - } - } - } - - jvm { - val processResourcesTaskName = - compilations[org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.MAIN_COMPILATION_NAME] - .processResourcesTaskName - - val jsBrowserDistribution = project.tasks.getByName("jsBrowserDistribution") - - project.tasks.getByName(processResourcesTaskName) { - duplicatesStrategy = DuplicatesStrategy.WARN - dependsOn(jsBrowserDistribution) - from(jsBrowserDistribution) - } - } - -} - -// -//internal fun Copy.copyJVMResources(configuration: Configuration): Unit = project.afterEvaluate { -// val projectDeps = configuration.allDependencies -// .filterIsInstance() -// .map { it.dependencyProject } -// -// projectDeps.forEach { dep -> -// dep.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { -// dep.tasks.findByName("jvmProcessResources")?.let { task -> -// dependsOn(task) -// from(task) -// } -// } -// dep.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { -// dep.tasks.findByName("processResources")?.let { task -> -// dependsOn(task) -// from(task) -// } -// } -// } -//} \ No newline at end of file +} \ No newline at end of file diff --git a/src/main/kotlin/space/kscience/gradle/internal/fx.kt b/src/main/kotlin/space/kscience/gradle/internal/fx.kt deleted file mode 100644 index 2733f46..0000000 --- a/src/main/kotlin/space/kscience/gradle/internal/fx.kt +++ /dev/null @@ -1,61 +0,0 @@ -package space.kscience.gradle.internal - -import org.apache.tools.ant.taskdefs.condition.Os -import org.gradle.api.Project -import org.gradle.kotlin.dsl.findByType -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler -import space.kscience.gradle.DependencyConfiguration -import space.kscience.gradle.FXModule -import space.kscience.gradle.FXPlatform - -internal val defaultPlatform: FXPlatform = when { - Os.isFamily(Os.FAMILY_WINDOWS) -> FXPlatform.WINDOWS - Os.isFamily(Os.FAMILY_MAC) -> FXPlatform.MAC - Os.isFamily(Os.FAMILY_UNIX) -> FXPlatform.LINUX - else -> error("Platform not recognized") -} - -private fun KotlinDependencyHandler.addFXDependencies( - modules: List, - configuration: DependencyConfiguration, - version: String = "14", - platform: FXPlatform = defaultPlatform -) { - modules.flatMap { it.dependencies.toList() + it }.distinct().forEach { - val notation = "org.openjfx:${it.artifact}:$version:${platform.id}" - when (configuration) { - DependencyConfiguration.API -> api(notation) - DependencyConfiguration.IMPLEMENTATION -> implementation(notation) - DependencyConfiguration.COMPILE_ONLY -> compileOnly(notation) - } - } -} - -internal fun Project.useFx( - modules: List, - 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 { - dependencies { - addFXDependencies(modules, configuration = configuration, version = version, platform = platform) - } - } - } - } - - pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { - extensions.findByType()?.apply { - sourceSets.findByName("main")?.apply { - dependencies { - addFXDependencies(modules, configuration = configuration, version = version, platform = platform) - } - } - } - } -}