Skip to content

Commit 5eed211

Browse files
authored
feat(plugin): dont use latest.release as default for the KMP dependency (#262)
* set kmp version * update * update test * update * Update CHANGELOG.md * updatE * add more tests
1 parent e88e2d0 commit 5eed211

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Improvements
6+
7+
- Plugin: dont use `latest.release` as default for the KMP dependency ([#262](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/262))
8+
59
### Dependencies
610

711
- **Gradle Plugin:** Bump default Cocoa SDK from v8.26.0 to v8.36.0 ([#261](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/261))

sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ buildConfig {
9595
"SentryCocoaVersion",
9696
provider { "\"${project.property("sentryCocoaVersion")}\"" }
9797
)
98+
buildConfigField(
99+
"String",
100+
"SentryKmpVersion",
101+
provider { "\"${project.property("versionName")}\"" }
102+
)
98103
}
99104

100105
detekt { config.setFrom(rootProject.files("../config/detekt/detekt.yml")) }

sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry.kotlin.multiplatform.gradle
22

3+
import io.sentry.BuildConfig
34
import org.gradle.api.Project
45
import org.gradle.api.provider.Property
56
import javax.inject.Inject
@@ -19,10 +20,10 @@ abstract class SourceSetAutoInstallExtension @Inject constructor(project: Projec
1920
/**
2021
* Overrides the default Sentry Kotlin Multiplatform SDK dependency version.
2122
*
22-
* Defaults to the latest version of the Sentry Kotlin Multiplatform SDK.
23+
* Defaults to the version of this plugin which is synchronized with the KMP SDK version.
2324
*/
2425
val sentryKmpVersion: Property<String> =
2526
objects
2627
.property(String::class.java)
27-
.convention("latest.release") // Replace with the actual default version
28+
.convention(BuildConfig.SentryKmpVersion)
2829
}

sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry.kotlin.multiplatform.gradle
22

3+
import io.sentry.BuildConfig
34
import org.gradle.api.plugins.ExtensionAware
45
import org.gradle.testfixtures.ProjectBuilder
56
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
@@ -11,6 +12,8 @@ import org.junit.jupiter.api.Assertions.assertNull
1112
import org.junit.jupiter.api.Assertions.assertTrue
1213
import org.junit.jupiter.api.Test
1314
import org.junit.jupiter.api.io.TempDir
15+
import org.junit.jupiter.params.ParameterizedTest
16+
import org.junit.jupiter.params.provider.ValueSource
1417
import java.io.File
1518

1619
class SentryPluginTest {
@@ -74,6 +77,38 @@ class SentryPluginTest {
7477
assertNotNull(project.extensions.getByName("commonMain"))
7578
}
7679

80+
@Test
81+
fun `default kmp version is set in commonMain extension`() {
82+
val project = ProjectBuilder.builder().build()
83+
project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle")
84+
85+
val sourceSetAutoInstallExtension = project.extensions.getByName("commonMain") as SourceSetAutoInstallExtension
86+
assertEquals(BuildConfig.SentryKmpVersion, sourceSetAutoInstallExtension.sentryKmpVersion.get())
87+
}
88+
89+
@Test
90+
fun `custom kmp version overrides default in commonMain extension`() {
91+
val project = ProjectBuilder.builder().build()
92+
project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle")
93+
94+
val autoInstallExtension = project.extensions.getByName("autoInstall") as AutoInstallExtension
95+
autoInstallExtension.commonMain.sentryKmpVersion.set("1.2.3")
96+
97+
assertEquals("1.2.3", autoInstallExtension.commonMain.sentryKmpVersion.get())
98+
}
99+
100+
@ParameterizedTest
101+
@ValueSource(strings = ["1.0.0", "2.3.4-SNAPSHOT", "latest.release"])
102+
fun `sentryKmpVersion accepts various version formats in commonMain extension`(version: String) {
103+
val project = ProjectBuilder.builder().build()
104+
project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle")
105+
106+
val autoInstallExtension = project.extensions.getByName("autoInstall") as AutoInstallExtension
107+
autoInstallExtension.commonMain.sentryKmpVersion.set(version)
108+
109+
assertEquals(version, autoInstallExtension.commonMain.sentryKmpVersion.get())
110+
}
111+
77112
@Test
78113
fun `when autoInstall is disabled, no installations are performed`() {
79114
val project = ProjectBuilder.builder().build()

0 commit comments

Comments
 (0)