Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin): dont use latest.release as default for the KMP dependency #262

Merged
merged 7 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")) }
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<String> =
objects
.property(String::class.java)
.convention("latest.release") // Replace with the actual default version
.convention(BuildConfig.SentryKmpVersion)
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
Loading