From 43dcf509fb776cdc731c300e266459858e57322d Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 4 Jun 2024 12:49:18 +0300 Subject: [PATCH] 0.15.4-2.0.0 --- CHANGELOG.md | 1 + gradle/libs.versions.toml | 2 +- .../kscience/gradle/KScienceExtension.kt | 23 ++++++++++--------- .../kscience/gradle/KScienceJVMPlugin.kt | 2 +- .../space/kscience/gradle/KScienceMPPlugin.kt | 8 ++++++- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 194f8f2..46afcf2 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 +- Pass `compose` extension to the kscience extension so compose dependencies could be called directly from kscience block ### Changed - Use ES6 modules by default in JS diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d285a12..e5acdb8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,7 +19,7 @@ ktor = "2.3.11" logback = "1.5.6" slf4j = "2.0.13" # @pin -tools = "0.15.3-kotlin-2.0.0" +tools = "0.15.4-kotlin-2.0.0" xmlutil = "0.86.3" yamlkt = "0.13.0" kover = "0.8.0" diff --git a/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt b/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt index 893c18d..97cc462 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt @@ -3,6 +3,7 @@ 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.plugins.ExtensionAware import org.gradle.api.provider.Property import org.gradle.api.tasks.Copy import org.gradle.api.tasks.testing.Test @@ -28,6 +29,7 @@ import space.kscience.gradle.internal.defaultKotlinJvmArgs import space.kscience.gradle.internal.fromJsDependencies import space.kscience.gradle.internal.requestPropertyOrNull import space.kscience.gradle.internal.useCommonDependency +import javax.inject.Inject public enum class DependencyConfiguration { API, @@ -52,7 +54,7 @@ public val Project.isInDevelopment: Boolean private const val defaultJdkVersion = 11 -public open class KScienceExtension(public val project: Project) { +public abstract class KScienceExtension @Inject constructor(public val project: Project): ExtensionAware { public val jdkVersionProperty: Property = project.objects.property().apply { set(defaultJdkVersion) @@ -352,7 +354,8 @@ public class KScienceNativeConfiguration(private val project: Project) { ): Unit = target(KScienceNativeTarget(preset, targetName, targetConfiguration)) } -public open class KScienceMppExtension(project: Project) : KScienceExtension(project) { +public abstract class KScienceMppExtension @Inject constructor(project: Project) : KScienceExtension(project) { + /** * Enable jvm target */ @@ -414,10 +417,6 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro */ @OptIn(ExperimentalWasmDsl::class) public fun wasm(block: KotlinWasmJsTargetDsl.() -> Unit = {}) { -// if (project.requestPropertyOrNull("kscience.wasm.disabled") == "true") { -// project.logger.warn("Wasm target is disabled with 'kscience.wasm.disabled' property") -// return -// } project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { project.configure { @@ -538,9 +537,11 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro } -internal inline fun Project.registerKScienceExtension(constructor: (Project) -> T): T { - extensions.findByType()?.let { return it } - return constructor(this).also { - extensions.add("kscience", it) - } +internal inline fun Project.registerKScienceExtension():T { +// extensions.findByType()?.let { return it } +// return constructor(this).also { +// extensions.add("kscience", it) +// } + + return extensions.create("kscience", T::class.java) } diff --git a/src/main/kotlin/space/kscience/gradle/KScienceJVMPlugin.kt b/src/main/kotlin/space/kscience/gradle/KScienceJVMPlugin.kt index 4cd7f56..1cb85e1 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceJVMPlugin.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceJVMPlugin.kt @@ -22,7 +22,7 @@ public open class KScienceJVMPlugin : Plugin { } else { logger.info("Kotlin JVM plugin is already present") } - val extension = registerKScienceExtension(::KScienceExtension) + val extension = registerKScienceExtension() //logger.info("Applying KScience configuration for JVM project") configure { diff --git a/src/main/kotlin/space/kscience/gradle/KScienceMPPlugin.kt b/src/main/kotlin/space/kscience/gradle/KScienceMPPlugin.kt index 90ab1f2..03cc281 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceMPPlugin.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceMPPlugin.kt @@ -21,7 +21,7 @@ public open class KScienceMPPlugin : Plugin { logger.info("Kotlin MPP plugin is already present") } - registerKScienceExtension(::KScienceMppExtension) + val kscience = registerKScienceExtension() configure { sourceSets { @@ -46,6 +46,12 @@ public open class KScienceMPPlugin : Plugin { } if (explicitApi == null) explicitApiWarning() + + //pass compose extension inside kscience extensions to make it available inside kscience block + plugins.withId("org.jetbrains.compose"){ + kscience.extensions.add("compose", (this@configure as org.gradle.api.plugins.ExtensionAware).extensions.getByName("compose")) + } + }