From 187b8e80768598ef0818bd0495121b668a893371 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 23 Aug 2022 16:55:08 +0300 Subject: [PATCH] Add public dev flag --- CHANGELOG.md | 1 + gradle/libs.versions.toml | 4 +- .../kscience/gradle/KScienceProjectPlugin.kt | 4 +- .../kscience/gradle/commonConfigurations.kt | 60 +++++++++++++++---- .../kscience/gradle/internal/publishing.kt | 7 +-- 5 files changed, 55 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f1acf0..9338245 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- Public `isInDevelopment` project flag - Add `-Xjdk-release` key ### Changed diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c859c44..97221a5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,8 +13,8 @@ kotlinx-datetime = "0.4.0" kotlinx-html = "0.7.5" kotlinx-knit = "0.4.0" kotlinx-nodejs = "0.0.7" -kotlinx-serialization = "1.4.0-RC" -ktor = "2.0.3" +kotlinx-serialization = "1.4.0" +ktor = "2.1.0" xmlutil = "0.84.2" yamlkt = "0.12.0" jsBom = "1.0.0-pre.353" diff --git a/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt index a48a27f..1adff44 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt @@ -114,7 +114,7 @@ public open class KScienceProjectPlugin : Plugin { apply() afterEvaluate { - if (isSnapshot()) { + if (isInDevelopment) { configure { validationDisabled = true } @@ -275,7 +275,7 @@ public open class KScienceProjectPlugin : Plugin { } // Disable API validation for snapshots - if (isSnapshot()) { + if (isInDevelopment) { extensions.findByType()?.apply { validationDisabled = true logger.warn("API validation is disabled for snapshot or dev version") diff --git a/src/main/kotlin/space/kscience/gradle/commonConfigurations.kt b/src/main/kotlin/space/kscience/gradle/commonConfigurations.kt index 97434e0..cb187ca 100644 --- a/src/main/kotlin/space/kscience/gradle/commonConfigurations.kt +++ b/src/main/kotlin/space/kscience/gradle/commonConfigurations.kt @@ -19,11 +19,24 @@ 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 { +private fun resolveKotlinVersion(): KotlinVersion { val (major, minor, patch) = KScienceVersions.kotlinVersion.split(".", "-") - return KotlinVersion(major.toInt(),minor.toInt(),patch.toInt()) + 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(), ) { @@ -160,19 +173,40 @@ public fun Project.configureKScience( } configuration.nativeConfiguration?.let { nativeConfiguration -> - val nativeTargets: List = nativeConfiguration.targets.values.mapNotNull { nativeTarget -> - when (nativeTarget.preset) { - KotlinNativePreset.linuxX64 -> linuxX64(nativeTarget.targetName, nativeTarget.targetConfiguration) - KotlinNativePreset.mingwX64 -> linuxX64(nativeTarget.targetName, nativeTarget.targetConfiguration) - KotlinNativePreset.macosX64 -> linuxX64(nativeTarget.targetName, nativeTarget.targetConfiguration) - KotlinNativePreset.iosX64 -> linuxX64(nativeTarget.targetName, nativeTarget.targetConfiguration) - KotlinNativePreset.iosArm64 -> linuxX64(nativeTarget.targetName, nativeTarget.targetConfiguration) - else -> { - logger.error("Native preset ${nativeTarget.preset} not recognised.") - null + val nativeTargets: List = + nativeConfiguration.targets.values.mapNotNull { nativeTarget -> + when (nativeTarget.preset) { + KotlinNativePreset.linuxX64 -> linuxX64( + nativeTarget.targetName, + nativeTarget.targetConfiguration + ) + + KotlinNativePreset.mingwX64 -> linuxX64( + nativeTarget.targetName, + nativeTarget.targetConfiguration + ) + + KotlinNativePreset.macosX64 -> linuxX64( + nativeTarget.targetName, + nativeTarget.targetConfiguration + ) + + KotlinNativePreset.iosX64 -> linuxX64( + nativeTarget.targetName, + nativeTarget.targetConfiguration + ) + + KotlinNativePreset.iosArm64 -> linuxX64( + nativeTarget.targetName, + nativeTarget.targetConfiguration + ) + + else -> { + logger.error("Native preset ${nativeTarget.preset} not recognised.") + null + } } } - } val nativeMain by creating { dependsOn(commonMain) diff --git a/src/main/kotlin/space/kscience/gradle/internal/publishing.kt b/src/main/kotlin/space/kscience/gradle/internal/publishing.kt index 679bd32..ac69ecf 100644 --- a/src/main/kotlin/space/kscience/gradle/internal/publishing.kt +++ b/src/main/kotlin/space/kscience/gradle/internal/publishing.kt @@ -11,6 +11,7 @@ import org.gradle.plugins.signing.SigningPlugin import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.targets +import space.kscience.gradle.isInDevelopment internal fun Project.requestPropertyOrNull(propertyName: String): String? = findProperty(propertyName) as? String ?: System.getenv(propertyName) @@ -108,8 +109,6 @@ internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit } } -internal fun Project.isSnapshot() = "dev" in version.toString() || version.toString().endsWith("SNAPSHOT") - internal fun Project.addGithubPublishing( githubOrg: String, githubProject: String, @@ -184,8 +183,8 @@ internal fun Project.addSonatypePublishing() { return } - if (isSnapshot()) { - logger.info("Sonatype publishing skipped for dev version") + if (isInDevelopment) { + logger.info("Sonatype publishing skipped for development version") return }