diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cd56464..f53cdc26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Improvements + +- Plugin: dont use `latest.release` as default for the KMP dependency ([#262](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/262)) + ### Dependencies - **Gradle Plugin:** Bump default Cocoa SDK from v8.26.0 to v8.36.0 ([#261](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/261)) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts index f457018c..af287258 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts @@ -95,6 +95,11 @@ buildConfig { "SentryCocoaVersion", provider { "\"${project.property("sentryCocoaVersion")}\"" } ) + buildConfigField( + "String", + "SentryKmpVersion", + provider { "\"${project.property("versionName")}\"" } + ) } detekt { config.setFrom(rootProject.files("../config/detekt/detekt.yml")) } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt index c2dff135..6e4ec17c 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt @@ -1,5 +1,6 @@ package io.sentry.kotlin.multiplatform.gradle +import io.sentry.BuildConfig import org.gradle.api.Project import org.gradle.api.provider.Property import javax.inject.Inject @@ -19,10 +20,10 @@ abstract class SourceSetAutoInstallExtension @Inject constructor(project: Projec /** * Overrides the default Sentry Kotlin Multiplatform SDK dependency version. * - * Defaults to the latest version of the Sentry Kotlin Multiplatform SDK. + * Defaults to the version of this plugin which is synchronized with the KMP SDK version. */ val sentryKmpVersion: Property = objects .property(String::class.java) - .convention("latest.release") // Replace with the actual default version + .convention(BuildConfig.SentryKmpVersion) } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt index dfa841aa..0cf1a25f 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt @@ -1,5 +1,6 @@ package io.sentry.kotlin.multiplatform.gradle +import io.sentry.BuildConfig import org.gradle.api.plugins.ExtensionAware import org.gradle.testfixtures.ProjectBuilder import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension @@ -11,6 +12,8 @@ import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import org.junit.jupiter.api.io.TempDir +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.ValueSource import java.io.File class SentryPluginTest { @@ -74,6 +77,38 @@ class SentryPluginTest { assertNotNull(project.extensions.getByName("commonMain")) } + @Test + fun `default kmp version is set in commonMain extension`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") + + val sourceSetAutoInstallExtension = project.extensions.getByName("commonMain") as SourceSetAutoInstallExtension + assertEquals(BuildConfig.SentryKmpVersion, sourceSetAutoInstallExtension.sentryKmpVersion.get()) + } + + @Test + fun `custom kmp version overrides default in commonMain extension`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") + + val autoInstallExtension = project.extensions.getByName("autoInstall") as AutoInstallExtension + autoInstallExtension.commonMain.sentryKmpVersion.set("1.2.3") + + assertEquals("1.2.3", autoInstallExtension.commonMain.sentryKmpVersion.get()) + } + + @ParameterizedTest + @ValueSource(strings = ["1.0.0", "2.3.4-SNAPSHOT", "latest.release"]) + fun `sentryKmpVersion accepts various version formats in commonMain extension`(version: String) { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") + + val autoInstallExtension = project.extensions.getByName("autoInstall") as AutoInstallExtension + autoInstallExtension.commonMain.sentryKmpVersion.set(version) + + assertEquals(version, autoInstallExtension.commonMain.sentryKmpVersion.get()) + } + @Test fun `when autoInstall is disabled, no installations are performed`() { val project = ProjectBuilder.builder().build()