From 4bfd042f96d48d2dcd07f2a88d658574c33ae630 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 11 Feb 2023 14:28:45 +0300 Subject: [PATCH] Kotlin 1.8.20-Beta --- CHANGELOG.md | 2 + gradle/libs.versions.toml | 7 +- .../kscience/gradle/KScienceExtension.kt | 73 +++++++++++++++++-- .../kscience/gradle/KScienceProjectPlugin.kt | 58 ++------------- 4 files changed, 80 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69e08f7..3f2d4ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,8 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - FX plugins - Unnecessary library shortcuts (html and datetime) +- deploy/release tasks ### Fixed +- issues with test sourcesets ### Security diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 66b58f2..3d160c9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] -tools = "0.14.0-kotlin-1.8.10" -kotlin = "1.8.10" +tools = "0.14.1-kotlin-1.8.20-Beta" +kotlin = "1.8.20-Beta" atomicfu = "0.19.0" binary-compatibility-validator = "0.12.1" changelog = "2.0.0" @@ -20,6 +20,7 @@ yamlkt = "0.12.0" jsBom = "1.0.0-pre.491" junit = "5.9.2" compose = "1.3.0" +logback = "1.4.5" [libraries] atomicfu-gradle = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "atomicfu" } @@ -78,6 +79,8 @@ xmlutil-serialization = { module = "io.github.pdvrieze.xmlutil:serialization", v yamlkt = { module = "net.mamoe.yamlkt:yamlkt", version.ref = "yamlkt" } +logback-classic = {module = "ch.qos.logback:logback-classic", version.ref = "logback"} + [plugins] changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" } diff --git a/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt b/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt index 2b2e4fa..6ae3c2d 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt @@ -15,6 +15,7 @@ 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.js.dsl.KotlinWasmTargetDsl import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlinx.jupyter.api.plugin.tasks.JupyterApiResourcesTask @@ -88,6 +89,36 @@ public open class KScienceExtension(public val project: Project) { SerializationTargets(sourceSet, configuration).block() } + public fun useKtor(version: String = KScienceVersions.ktorVersion): Unit = with(project) { + pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { + configure { + sourceSets.findByName("commonMain")?.apply { + dependencies { + api(platform("io.ktor:ktor-bom:$version")) + } + } + } + } + pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { + configure { + sourceSets.findByName("main")?.apply { + dependencies { + api(platform("io.ktor:ktor-bom:$version")) + } + } + } + } + pluginManager.withPlugin("org.jetbrains.kotlin.js") { + configure { + sourceSets.findByName("main")?.apply { + dependencies { + api(platform("io.ktor:ktor-bom:$version")) + } + } + } + } + } + /** * Apply jupyter plugin and add entry point for the jupyter library. * If left empty applies a plugin without declaring library producers @@ -154,7 +185,6 @@ public open class KScienceExtension(public val project: Project) { } } - public class DefaultSourceSet(public val key: String) public fun dependencies( @@ -182,13 +212,17 @@ public open class KScienceExtension(public val project: Project) { } project.extensions.findByType()?.apply { - js(IR) { + targets.withType { binaries.executable() } targets.withType { binaries.executable() } + + targets.withType { + binaries.executable() + } } } @@ -203,12 +237,21 @@ public open class KScienceExtension(public val project: Project) { } } + public operator fun DefaultSourceSet.invoke(dependencyBlock: KotlinDependencyHandler.() -> Unit) { + dependencies(this, dependencyBlock) + } + + public val commonMain: DefaultSourceSet get() = DefaultSourceSet("commonMain") + public val commonTest: DefaultSourceSet get() = DefaultSourceSet("commonTest") + public val jvmMain: DefaultSourceSet get() = DefaultSourceSet("jvmMain") public val jvmTest: DefaultSourceSet get() = DefaultSourceSet("jvmTest") public val jsMain: DefaultSourceSet get() = DefaultSourceSet("jsMain") public val jsTest: DefaultSourceSet get() = DefaultSourceSet("jsTest") public val nativeMain: DefaultSourceSet get() = DefaultSourceSet("nativeMain") public val nativeTest: DefaultSourceSet get() = DefaultSourceSet("nativeTest") + public val wasmMain: DefaultSourceSet get() = DefaultSourceSet("wasmMain") + public val wasmTest: DefaultSourceSet get() = DefaultSourceSet("wasmTest") } @@ -286,7 +329,7 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro block() } sourceSets { - getByName("jvmMain") { + getByName("jvmTest") { dependencies { implementation(kotlin("test-junit5")) implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}") @@ -313,6 +356,13 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro browser() block() } + sourceSets { + getByName("jsTest") { + dependencies { + implementation(kotlin("test-js")) + } + } + } } (project.tasks.findByName("jsProcessResources") as? Copy)?.apply { fromJsDependencies("jsRuntimeClasspath") @@ -320,9 +370,20 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro } } + public fun wasm(block: KotlinWasmTargetDsl.() -> Unit = {}) { + project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { + project.configure { + wasm { + browser() + block() + } + } + } + } + public fun jvmAndJs() { - jvm {} - js {} + jvm() + js() } /** @@ -386,7 +447,7 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro nativeTarget.targetConfiguration ) - KotlinNativePreset.macosArm64 -> macosX64( + KotlinNativePreset.macosArm64 -> macosArm64( nativeTarget.targetName, nativeTarget.targetConfiguration ) diff --git a/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt index 35a55d7..c6b135f 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt @@ -5,7 +5,6 @@ import kotlinx.validation.BinaryCompatibilityValidatorPlugin import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.publish.maven.MavenPom -import org.gradle.api.publish.maven.tasks.PublishToMavenRepository import org.gradle.kotlin.dsl.* import org.jetbrains.changelog.ChangelogPlugin import org.jetbrains.changelog.ChangelogPluginExtension @@ -18,7 +17,6 @@ import space.kscience.gradle.internal.* */ public class KSciencePublishingExtension(public val project: Project) { private var isVcsInitialized = false - internal val repositoryNames = mutableSetOf() /** * Configures Git repository (sources) for the publication. @@ -55,18 +53,16 @@ public class KSciencePublishingExtension(public val project: Project) { * * @param githubProject the GitHub project. * @param githubOrg the GitHub user or organization. - * @param addToRelease publish packages in the `release` task to the GitHub repository. + * @param deploy publish packages in the `deploy` task to the GitHub repository. */ public fun github( githubOrg: String, githubProject: String, - addToRelease: Boolean = project.requestPropertyOrNull("publishing.github") == "true", + deploy: Boolean = project.requestPropertyOrNull("publishing.github") == "true", ) { - - if (addToRelease) { + if (deploy) { try { project.addGithubPublishing(githubOrg, githubProject) - repositoryNames += "github" } catch (t: Throwable) { project.logger.error("Failed to set up github publication", t) } @@ -77,15 +73,12 @@ public class KSciencePublishingExtension(public val project: Project) { * Adds Space Packages Maven repository to publishing. * * @param spaceRepo the repository URL. - * @param addToRelease publish packages in the `release` task to the Space repository. + * @param deploy publish packages in the `deploy` task to the Space repository. */ public fun space( spaceRepo: String, - addToRelease: Boolean = project.requestPropertyOrNull("publishing.space") != "false", ) { project.addSpacePublishing(spaceRepo) - - if (addToRelease) repositoryNames += "space" } /** @@ -93,13 +86,9 @@ public class KSciencePublishingExtension(public val project: Project) { * * @param addToRelease publish packages in the `release` task to the Sonatype repository. */ - public fun sonatype( - addToRelease: Boolean = (project.requestPropertyOrNull("publishing.sonatype") != "false"), - ) { + public fun sonatype() { require(isVcsInitialized) { "The project vcs is not set up use 'pom' method to do so" } project.addSonatypePublishing() - - if (addToRelease) repositoryNames += "sonatype" } } @@ -227,13 +216,6 @@ public open class KScienceProjectPlugin : Plugin { dependsOn(generateReadme) } - - val releaseAll by tasks.creating { - group = RELEASE_GROUP - description = "Publish development or production release based on version suffix" - dependsOn(generateReadme) - } - tasks.create("version") { group = "publishing" val versionFile = project.buildDir.resolve("project-version.txt") @@ -245,34 +227,6 @@ public open class KScienceProjectPlugin : Plugin { } } - allprojects { - afterEvaluate { - ksciencePublish.repositoryNames.forEach { repositoryName -> - val repositoryNameCapitalized = repositoryName.capitalize() - - val pattern = "publish(?.*)PublicationTo${repositoryNameCapitalized}Repository" - .toRegex() - - tasks.withType().forEach forEachPublication@{ - val matchResult = pattern.matchEntire(it.name) ?: return@forEachPublication - val publicationName = matchResult.groups["publication"]!!.value.capitalize() - val releaseTaskName = "release$publicationName" - - val targetReleaseTask = - rootProject.tasks.findByName(releaseTaskName) ?: rootProject.tasks.create(releaseTaskName) { - group = RELEASE_GROUP - description = - "Publish platform release artifact for $publicationName to all repositories" - } - - releaseAll.dependsOn(targetReleaseTask) - - targetReleaseTask.dependsOn(it) - } - } - } - } - // Disable API validation for snapshots if (isInDevelopment) { extensions.findByType()?.apply { @@ -288,6 +242,6 @@ public open class KScienceProjectPlugin : Plugin { } public companion object { - public const val RELEASE_GROUP: String = "release" + public const val DEPLOY_GROUP: String = "deploy" } }