From 7129e48a2b765c18262f4ec9f62c1701c1c946b9 Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Tue, 17 Nov 2026 15:16:13 +0100 Subject: [PATCH] build(compose): Move sentry-compose to the KMP Android library plugin KMP modules can't combine org.jetbrains.kotlin.multiplatform with com.android.library once AGP's built-in Kotlin is on, which the new AGP DSL needs. sentry-compose now uses com.android.kotlin.multiplatform.library. The Kotlin Gradle plugin's ABI validation skips the new Android target, so build-logic dumps it with the same abi-tools and hooks into checkKotlinAbi and updateKotlinAbi. The JDK target, Robolectric and CodeQL conventions learn the new plugin, lint needs com.android.lint, and detekt's test excludes gain the androidHostTest source set. The plugin has no BuildConfig, so the version comes from a generated internal constant and io.sentry.compose.BuildConfig is gone. Co-Authored-By: Claude Opus 5.5 --- .claude/skills/test/SKILL.md | 2 +- build-logic/build.gradle.kts | 1 + .../io/sentry/gradle/JdkTargetConvention.kt | 35 +++- .../sentry/gradle/KmpAndroidAbiValidation.kt | 173 ++++++++++++++++++ .../gradle/SentryApiValidationPlugin.kt | 3 + .../sentry/gradle/SentryRobolectricPlugin.kt | 35 ++-- build.gradle.kts | 4 + detekt.yml | 61 +++++- gradle/libs.versions.toml | 1 + sentry-compose/api/android/sentry-compose.api | 8 - sentry-compose/build.gradle.kts | 111 +++++------ sentry-compose/gradle.properties | 2 - .../foundation/GestureModifierStubs.kt | 0 .../sentry/compose/ComposeIntegrationTests.kt | 0 .../compose/SentryLifecycleObserverTest.kt | 0 .../compose/SentryModifierComposeTest.kt | 0 .../io/sentry/compose/SentryTracedTest.kt | 0 .../ComposeGestureTargetLocatorTest.kt | 0 .../ComposeViewHierarchyExporterTest.kt | 0 .../compose/SentryNavigationIntegration.kt | 2 +- .../gestures/ComposeGestureTargetLocator.kt | 4 +- 21 files changed, 348 insertions(+), 94 deletions(-) create mode 100644 build-logic/src/main/kotlin/io/sentry/gradle/KmpAndroidAbiValidation.kt rename sentry-compose/src/{androidUnitTest => androidHostTest}/kotlin/androidx/compose/foundation/GestureModifierStubs.kt (100%) rename sentry-compose/src/{androidUnitTest => androidHostTest}/kotlin/io/sentry/compose/ComposeIntegrationTests.kt (100%) rename sentry-compose/src/{androidUnitTest => androidHostTest}/kotlin/io/sentry/compose/SentryLifecycleObserverTest.kt (100%) rename sentry-compose/src/{androidUnitTest => androidHostTest}/kotlin/io/sentry/compose/SentryModifierComposeTest.kt (100%) rename sentry-compose/src/{androidUnitTest => androidHostTest}/kotlin/io/sentry/compose/SentryTracedTest.kt (100%) rename sentry-compose/src/{androidUnitTest => androidHostTest}/kotlin/io/sentry/compose/gestures/ComposeGestureTargetLocatorTest.kt (100%) rename sentry-compose/src/{androidUnitTest => androidHostTest}/kotlin/io/sentry/compose/viewhierarchy/ComposeViewHierarchyExporterTest.kt (100%) diff --git a/.claude/skills/test/SKILL.md b/.claude/skills/test/SKILL.md index 5e19619b1b2..417c75b79a9 100644 --- a/.claude/skills/test/SKILL.md +++ b/.claude/skills/test/SKILL.md @@ -46,7 +46,7 @@ Determine the Gradle test task: | Module Pattern | Test Task | |---------------|-----------| | `sentry-android-*` | `testReleaseUnitTest` | -| `sentry-compose*` | `testReleaseUnitTest` | +| `sentry-compose*` | `testAndroidHostTest` | | `*-android` | `testReleaseUnitTest` | | Everything else | `test` | diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index db40bf74435..2c6e8ff13ae 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -9,6 +9,7 @@ dependencies { implementation(libs.vanniktechMavenPublishLib) implementation(libs.asm) compileOnly(libs.kotlin.gradle.plugin) + compileOnly(libs.kotlin.abi.tools.api) compileOnly(libs.android.gradle.plugin) } diff --git a/build-logic/src/main/kotlin/io/sentry/gradle/JdkTargetConvention.kt b/build-logic/src/main/kotlin/io/sentry/gradle/JdkTargetConvention.kt index 0b4c54ce906..2caa352dca0 100644 --- a/build-logic/src/main/kotlin/io/sentry/gradle/JdkTargetConvention.kt +++ b/build-logic/src/main/kotlin/io/sentry/gradle/JdkTargetConvention.kt @@ -1,7 +1,10 @@ package io.sentry.gradle import com.android.build.api.artifact.SingleArtifact +import com.android.build.api.dsl.KotlinMultiplatformAndroidHostTestCompilation +import com.android.build.api.dsl.KotlinMultiplatformAndroidLibraryTarget import com.android.build.api.dsl.LibraryExtension +import com.android.build.api.variant.KotlinMultiplatformAndroidComponentsExtension import com.android.build.api.variant.LibraryAndroidComponentsExtension import org.gradle.api.JavaVersion import org.gradle.api.Plugin @@ -81,6 +84,15 @@ class JdkTargetConvention : Plugin { } } } + project.plugins.withId("com.android.kotlin.multiplatform.library") { + project.extensions + .getByType(KotlinMultiplatformAndroidComponentsExtension::class.java) + .onVariants { variant -> + verifyMethodParameters.configure { + archives.from(variant.artifacts.get(SingleArtifact.AAR)) + } + } + } // Only works for non-android modules // See https://issuetracker.google.com/issues/278800528 project.plugins.withId("java-library") { @@ -112,6 +124,22 @@ class JdkTargetConvention : Plugin { listOf("com.android.library", "com.android.application").forEach { pluginId -> project.plugins.withId(pluginId) { project.targetBuildJdkForUnitTests() } } + project.plugins.withId("com.android.kotlin.multiplatform.library") { + project.extensions + .getByType(KotlinMultiplatformExtension::class.java) + .targets + .withType(KotlinMultiplatformAndroidLibraryTarget::class.java) + .configureEach { + aarMetadata { minCompileSdk = project.minSdk() } + compilations + .withType(KotlinMultiplatformAndroidHostTestCompilation::class.java) + .configureEach { + compileTaskProvider.configure { + compilerOptions.jvmTarget.set(JvmTarget.fromTarget(BUILD_JDK.toString())) + } + } + } + } } private fun Project.minSdk(): Int = @@ -133,13 +161,6 @@ class JdkTargetConvention : Plugin { plugins.withId("org.jetbrains.kotlin.android") { extensions.getByType(KotlinAndroidProjectExtension::class.java).target.targetBuildJdk() } - plugins.withId("org.jetbrains.kotlin.multiplatform") { - extensions - .getByType(KotlinMultiplatformExtension::class.java) - .targets - .withType(KotlinAndroidTarget::class.java) - .configureEach { targetBuildJdk() } - } } private fun KotlinAndroidTarget.targetBuildJdk() { diff --git a/build-logic/src/main/kotlin/io/sentry/gradle/KmpAndroidAbiValidation.kt b/build-logic/src/main/kotlin/io/sentry/gradle/KmpAndroidAbiValidation.kt new file mode 100644 index 00000000000..6f13307b25e --- /dev/null +++ b/build-logic/src/main/kotlin/io/sentry/gradle/KmpAndroidAbiValidation.kt @@ -0,0 +1,173 @@ +package io.sentry.gradle + +import com.android.build.api.dsl.KotlinMultiplatformAndroidLibraryTarget +import java.io.File +import javax.inject.Inject +import org.gradle.api.DefaultTask +import org.gradle.api.GradleException +import org.gradle.api.Project +import org.gradle.api.file.ConfigurableFileCollection +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.SetProperty +import org.gradle.api.tasks.CacheableTask +import org.gradle.api.tasks.Classpath +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputFiles +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.PathSensitive +import org.gradle.api.tasks.PathSensitivity +import org.gradle.api.tasks.TaskAction +import org.gradle.work.DisableCachingByDefault +import org.gradle.workers.WorkAction +import org.gradle.workers.WorkParameters +import org.gradle.workers.WorkerExecutor +import org.jetbrains.kotlin.abi.tools.AbiFilters +import org.jetbrains.kotlin.abi.tools.AbiTools +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion + +/** + * The Kotlin Gradle plugin's ABI validation only dumps JVM and legacy `androidTarget` targets, so a + * module on the KMP Android library plugin would silently stop checking its Android ABI. This dumps + * that target with the same ABI tools the Kotlin Gradle plugin uses, into the same + * `api//.api` file, and hooks into `checkKotlinAbi` and `updateKotlinAbi`. + */ +internal fun Project.validateKmpAndroidAbi(extension: ApiValidationExtension) { + val abiTools = + configurations.detachedConfiguration( + dependencies.create("org.jetbrains.kotlin:abi-tools:${getKotlinPluginVersion()}") + ) + + extensions + .getByType(KotlinMultiplatformExtension::class.java) + .targets + .withType(KotlinMultiplatformAndroidLibraryTarget::class.java) + .all { + val targetName = name + val capitalized = targetName.replaceFirstChar { it.uppercase() } + val dump = + tasks.register("dump${capitalized}KotlinAbi", DumpKmpAndroidAbi::class.java) { + description = "Dumps the public ABI of the $targetName target." + classpath.from(abiTools) + classes.from(compilations.getByName("main").output.classesDirs) + ignoredPackages.set(extension.ignoredPackages) + dumpFile.set(layout.buildDirectory.file("kotlin/abi-$targetName/${project.name}.api")) + } + val referenceDump = layout.projectDirectory.file("api/$targetName/${project.name}.api") + + val check = + tasks.register("check${capitalized}KotlinAbi", CheckKmpAndroidAbi::class.java) { + description = "Checks the public ABI of the $targetName target against its dump." + group = "verification" + classpath.from(abiTools) + actual.set(dump.flatMap { it.dumpFile }) + expected.set(referenceDump) + } + tasks.named("checkKotlinAbi").configure { dependsOn(check) } + + val update = + tasks.register("update${capitalized}KotlinAbi", UpdateKmpAndroidAbi::class.java) { + description = "Writes the public ABI of the $targetName target to its dump." + actual.set(dump.flatMap { it.dumpFile }) + expected.set(referenceDump) + } + tasks.named("updateKotlinAbi").configure { dependsOn(update) } + } +} + +@CacheableTask +abstract class DumpKmpAndroidAbi @Inject constructor(private val workers: WorkerExecutor) : + DefaultTask() { + @get:Classpath abstract val classpath: ConfigurableFileCollection + + @get:Classpath abstract val classes: ConfigurableFileCollection + + @get:Input abstract val ignoredPackages: SetProperty + + @get:OutputFile abstract val dumpFile: RegularFileProperty + + @TaskAction + fun dump() { + workers + .classLoaderIsolation { classpath.from(this@DumpKmpAndroidAbi.classpath) } + .submit(DumpAbiAction::class.java) { + classes.from(this@DumpKmpAndroidAbi.classes) + excludedClasses.set(ignoredPackages.map { packages -> packages.map { "$it.**" }.toSet() }) + dumpFile.set(this@DumpKmpAndroidAbi.dumpFile) + } + } +} + +@DisableCachingByDefault(because = "Comparing two small files is cheaper than caching it") +abstract class CheckKmpAndroidAbi @Inject constructor(private val workers: WorkerExecutor) : + DefaultTask() { + @get:Classpath abstract val classpath: ConfigurableFileCollection + + @get:InputFiles @get:PathSensitive(PathSensitivity.NONE) abstract val actual: RegularFileProperty + + // InputFiles rather than InputFile, so that a missing dump fails with the message below. + @get:InputFiles + @get:PathSensitive(PathSensitivity.NONE) + abstract val expected: RegularFileProperty + + @TaskAction + fun check() { + val expectedFile = expected.get().asFile + if (!expectedFile.exists()) { + throw GradleException( + "The ABI dump ${expectedFile.path} is missing. Run updateKotlinAbi to create it." + ) + } + workers + .classLoaderIsolation { classpath.from(this@CheckKmpAndroidAbi.classpath) } + .submit(CheckAbiAction::class.java) { + expected.set(expectedFile) + actual.set(this@CheckKmpAndroidAbi.actual) + } + } +} + +@DisableCachingByDefault(because = "Copies one file into the source tree") +abstract class UpdateKmpAndroidAbi : DefaultTask() { + @get:InputFiles @get:PathSensitive(PathSensitivity.NONE) abstract val actual: RegularFileProperty + + @get:OutputFile abstract val expected: RegularFileProperty + + @TaskAction + fun update() { + actual.get().asFile.copyTo(expected.get().asFile, overwrite = true) + } +} + +interface DumpAbiParameters : WorkParameters { + val classes: ConfigurableFileCollection + val excludedClasses: SetProperty + val dumpFile: RegularFileProperty +} + +abstract class DumpAbiAction : WorkAction { + override fun execute() { + val filters = + AbiFilters(emptySet(), parameters.excludedClasses.get(), emptySet(), emptySet()) + val classFiles = parameters.classes.asFileTree.matching { include("**/*.class") }.files + parameters.dumpFile.get().asFile.bufferedWriter().use { + AbiTools.getInstance().printJvmDump(it, classFiles, filters) + } + } +} + +interface CheckAbiParameters : WorkParameters { + val expected: RegularFileProperty + val actual: RegularFileProperty +} + +abstract class CheckAbiAction : WorkAction { + override fun execute() { + val expected: File = parameters.expected.get().asFile + val actual: File = parameters.actual.get().asFile + val diff = AbiTools.getInstance().filesDiff(expected, actual) ?: return + throw GradleException( + "The public ABI of ${expected.path} changed. Run updateKotlinAbi if that is intended.\n$diff" + ) + } +} diff --git a/build-logic/src/main/kotlin/io/sentry/gradle/SentryApiValidationPlugin.kt b/build-logic/src/main/kotlin/io/sentry/gradle/SentryApiValidationPlugin.kt index f4c1dca5948..3472446935b 100644 --- a/build-logic/src/main/kotlin/io/sentry/gradle/SentryApiValidationPlugin.kt +++ b/build-logic/src/main/kotlin/io/sentry/gradle/SentryApiValidationPlugin.kt @@ -31,6 +31,9 @@ class SentryApiValidationPlugin : Plugin { KOTLIN_PLUGIN_IDS.forEach { project.pluginManager.withPlugin(it) { enable(project, extension) } } + project.pluginManager.withPlugin("com.android.kotlin.multiplatform.library") { + project.validateKmpAndroidAbi(extension) + } } private fun enable(project: Project, extension: ApiValidationExtension) { diff --git a/build-logic/src/main/kotlin/io/sentry/gradle/SentryRobolectricPlugin.kt b/build-logic/src/main/kotlin/io/sentry/gradle/SentryRobolectricPlugin.kt index a996574f7da..1504d286a7c 100644 --- a/build-logic/src/main/kotlin/io/sentry/gradle/SentryRobolectricPlugin.kt +++ b/build-logic/src/main/kotlin/io/sentry/gradle/SentryRobolectricPlugin.kt @@ -15,6 +15,7 @@ import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.testing.Test import org.gradle.process.CommandLineArgumentProvider import org.gradle.work.DisableCachingByDefault @@ -69,18 +70,30 @@ class SentryRobolectricPlugin : Plugin { propertiesFile.set(project.layout.buildDirectory.file("robolectric/deps.properties")) } + val useGradleCachedJars: (Test) -> Unit = { test -> + // The properties file holds absolute paths, so it can't be a test input without breaking + // build cache hits across machines. The jars are the input instead. + test.dependsOn(writeDeps) + test.jvmArgumentProviders.add( + project.objects.newInstance(RobolectricDepsArgument::class.java).apply { + androidAllJars.from(coordinatesToJar.values) + propertiesFile.set(writeDeps.flatMap { it.propertiesFile }) + } + ) + } + project.plugins.withId("com.android.library") { - project.extensions.getByType(LibraryExtension::class.java).testOptions.unitTests.all { test -> - // The properties file holds absolute paths, so it can't be a test input without breaking - // build cache hits across machines. The jars are the input instead. - test.dependsOn(writeDeps) - test.jvmArgumentProviders.add( - project.objects.newInstance(RobolectricDepsArgument::class.java).apply { - androidAllJars.from(coordinatesToJar.values) - propertiesFile.set(writeDeps.flatMap { it.propertiesFile }) - } - ) - } + project.extensions + .getByType(LibraryExtension::class.java) + .testOptions + .unitTests + .all(useGradleCachedJars) + } + project.plugins.withId("com.android.kotlin.multiplatform.library") { + project.tasks + .withType(Test::class.java) + .matching { it.name == "testAndroidHostTest" } + .configureEach(useGradleCachedJars) } } } diff --git a/build.gradle.kts b/build.gradle.kts index ef0248024d5..6f1e1ce21d3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -56,6 +56,10 @@ tasks.register("buildForCodeQL") { proj.tasks.findByName("compileReleaseUnitTestSources")?.let { testTask -> this.dependsOn(testTask) } + } else if (proj.plugins.hasPlugin("com.android.kotlin.multiplatform.library")) { + proj.tasks.findByName("compileAndroidHostTest")?.let { testTask -> + this.dependsOn(testTask) + } } else { proj.tasks.findByName("testClasses")?.let { testTask -> this.dependsOn(testTask) diff --git a/detekt.yml b/detekt.yml index e8a01a87135..0416800fc2a 100644 --- a/detekt.yml +++ b/detekt.yml @@ -1,16 +1,59 @@ +# detekt's defaults exclude test sources from these rules, but its list predates the KMP Android +# library plugin's androidHostTest source set. A rule's excludes replace the default list, so this +# repeats it with androidHostTest added. +comments: + KDocReferencesNonPublicProperty: + excludes: &testSources + - '**/test/**' + - '**/androidTest/**' + - '**/commonTest/**' + - '**/jvmTest/**' + - '**/androidUnitTest/**' + - '**/androidHostTest/**' + - '**/androidInstrumentedTest/**' + - '**/jsTest/**' + - '**/iosTest/**' + UndocumentedPublicClass: + excludes: *testSources + UndocumentedPublicFunction: + excludes: *testSources + UndocumentedPublicProperty: + excludes: *testSources +complexity: + StringLiteralDuplication: + excludes: *testSources + TooManyFunctions: + excludes: *testSources + ignoreAnnotatedFunctions: ['Preview'] +exceptions: + InstanceOfCheckForException: + excludes: *testSources + ThrowingExceptionsWithoutMessageOrCause: + excludes: *testSources + TooGenericExceptionCaught: + excludes: *testSources +naming: + FunctionNaming: + excludes: *testSources + ignoreAnnotated: ['Composable'] + TopLevelPropertyNaming: + # Accept both SCREAMING_CASE and Compose's PascalCase constants. + constantPattern: '[A-Z][_A-Za-z0-9]*' +performance: + ForEachOnRange: + excludes: *testSources + SpreadOperator: + excludes: *testSources +potential-bugs: + LateinitUsage: + excludes: *testSources + UnsafeCallOnNullableType: + excludes: *testSources style: ReturnCount: max: 3 MagicNumber: + excludes: *testSources ignorePropertyDeclaration: true UnusedPrivateMember: ignoreAnnotated: ['Preview'] -naming: - FunctionNaming: - ignoreAnnotated: ['Composable'] - TopLevelPropertyNaming: - # Accept both SCREAMING_CASE and Compose's PascalCase constants. - constantPattern: '[A-Z][_A-Za-z0-9]*' -complexity: - TooManyFunctions: - ignoreAnnotatedFunctions: ['Preview'] diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5cf78106317..cf47e95e47b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -167,6 +167,7 @@ leakcanary = { module = "com.squareup.leakcanary:leakcanary-android", version = lottie-compose = { module = "com.airbnb.android:lottie-compose", version = "6.7.1" } logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" } kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } +kotlin-abi-tools-api = { module = "org.jetbrains.kotlin:abi-tools-api", version.ref = "kotlin" } android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "agp" } asm = { module = "org.ow2.asm:asm", version = "9.9" } nopen-annotations = { module = "com.jakewharton.nopen:nopen-annotations", version.ref = "nopen" } diff --git a/sentry-compose/api/android/sentry-compose.api b/sentry-compose/api/android/sentry-compose.api index 356e507c1aa..10e701f0874 100644 --- a/sentry-compose/api/android/sentry-compose.api +++ b/sentry-compose/api/android/sentry-compose.api @@ -1,11 +1,3 @@ -public final class io/sentry/compose/BuildConfig { - public static final field BUILD_TYPE Ljava/lang/String; - public static final field DEBUG Z - public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String; - public static final field VERSION_NAME Ljava/lang/String; - public fun ()V -} - public final class io/sentry/compose/LocalSentrySpanKt { public static final fun getLocalSentrySpan ()Landroidx/compose/runtime/ProvidableCompositionLocal; } diff --git a/sentry-compose/build.gradle.kts b/sentry-compose/build.gradle.kts index d3628be16f3..a0a64137f26 100644 --- a/sentry-compose/build.gradle.kts +++ b/sentry-compose/build.gradle.kts @@ -6,7 +6,8 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinVersion plugins { alias(libs.plugins.kotlin.multiplatform) alias(libs.plugins.kotlin.compose) - id("com.android.library") + id("com.android.kotlin.multiplatform.library") + id("com.android.lint") alias(libs.plugins.gradle.versions) id("io.sentry.detekt") alias(libs.plugins.dokka) @@ -19,16 +20,67 @@ plugins { id("io.sentry.robolectric") } +// The KMP Android library plugin has no BuildConfig, so the version is generated as a Kotlin +// source. +val generateSentryComposeVersion = + tasks.register("generateSentryComposeVersion") { + val version = project.version.toString() + val outputDir = layout.buildDirectory.dir("generated/sentryComposeVersion") + inputs.property("version", version) + outputs.dir(outputDir) + doLast { + val file = outputDir.get().file("io/sentry/compose/SentryComposeVersion.kt").asFile + file.parentFile.mkdirs() + file.writeText( + """ + |package io.sentry.compose + | + |internal const val SENTRY_COMPOSE_VERSION_NAME: String = "$version" + |""" + .trimMargin(), + ) + } + } + kotlin { explicitApi() - androidTarget { + android { + namespace = "io.sentry.compose" + compileSdk { + version = + release(libs.versions.compileSdk.get().toInt()) { + minorApiLevel = libs.versions.compileSdkMinor.get().toInt() + } + } + minSdk = libs.versions.minSdk.get().toInt() + + androidResources { enable = true } + + optimization { + consumerKeepRules.publish = true + consumerKeepRules.file("proguard-rules.pro") + } + + withHostTest { + isReturnDefaultValues = true + isIncludeAndroidResources = true + } + + lint { + warningsAsErrors = true + checkDependencies = true + + // Lint 9.5 can't load the custom checks bundled with older androidx.lifecycle releases and + // reports that it skips them. They only cover lifecycle APIs this module doesn't call. + disable += "ObsoleteLintCustomCheck" + } + compilerOptions { jvmTarget.set(JvmTarget.JVM_1_8) apiVersion.set(KotlinVersion.KOTLIN_1_9) languageVersion.set(KotlinVersion.KOTLIN_1_9) } - publishLibraryVariants("release") } jvm("desktop") { compilerOptions { @@ -56,6 +108,7 @@ kotlin { } } getByName("androidMain") { + kotlin.srcDir(generateSentryComposeVersion) dependencies { api(projects.sentry) api(projects.sentryAndroidNavigation) @@ -65,7 +118,7 @@ kotlin { implementation(libs.androidx.lifecycle.common.java8) } } - getByName("androidUnitTest") { + getByName("androidHostTest") { dependencies { implementation(libs.androidx.compose.ui.test.junit4) implementation(libs.androidx.navigation.compose) @@ -82,56 +135,8 @@ kotlin { } } -android { - compileSdk = libs.versions.compileSdk.get().toInt() - compileSdkMinor = libs.versions.compileSdkMinor.get().toInt() - namespace = "io.sentry.compose" - - defaultConfig { - minSdk = libs.versions.minSdk.get().toInt() - - // for AGP 4.1 - buildConfigField("String", "VERSION_NAME", "\"${project.version}\"") - } - - buildTypes { - getByName("debug") { consumerProguardFiles("proguard-rules.pro") } - getByName("release") { consumerProguardFiles("proguard-rules.pro") } - } - - // AGP 9 only generates unit tests for the testBuildType. The debug variant is - // disabled, so unit tests must target release to run at all. - testBuildType = "release" - - testOptions { - animationsDisabled = true - unitTests.apply { - isReturnDefaultValues = true - isIncludeAndroidResources = true - } - } - - lint { - warningsAsErrors = true - checkDependencies = true - - // We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks. - checkReleaseBuilds = false - - // Lint 9.5 can't load the custom checks bundled with older androidx.lifecycle releases and - // reports that it skips them. They only cover lifecycle APIs this module doesn't call. - disable += "ObsoleteLintCustomCheck" - } - - buildFeatures { buildConfig = true } - - androidComponents.beforeVariants { - it.enable = !Config.Android.shouldSkipDebugVariant(it.buildType) - } -} - // The default detekt source set is src/{main,test}, which doesn't exist in a multiplatform module. -detekt { source.setFrom("src/androidMain/kotlin", "src/androidUnitTest/kotlin") } +detekt { source.setFrom("src/androidMain/kotlin", "src/androidHostTest/kotlin") } tasks.withType().configureEach { // Target version of the generated JVM bytecode. It is used for type resolution. diff --git a/sentry-compose/gradle.properties b/sentry-compose/gradle.properties index 5ad025123aa..feb4ddee322 100644 --- a/sentry-compose/gradle.properties +++ b/sentry-compose/gradle.properties @@ -1,6 +1,4 @@ kotlin.mpp.stability.nowarn=true -kotlin.mpp.androidSourceSetLayoutVersion=2 # Don't show Dokka plugin's long message on every build -kotlin.mpp.androidGradlePluginCompatibility.nowarn=true org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true diff --git a/sentry-compose/src/androidUnitTest/kotlin/androidx/compose/foundation/GestureModifierStubs.kt b/sentry-compose/src/androidHostTest/kotlin/androidx/compose/foundation/GestureModifierStubs.kt similarity index 100% rename from sentry-compose/src/androidUnitTest/kotlin/androidx/compose/foundation/GestureModifierStubs.kt rename to sentry-compose/src/androidHostTest/kotlin/androidx/compose/foundation/GestureModifierStubs.kt diff --git a/sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/ComposeIntegrationTests.kt b/sentry-compose/src/androidHostTest/kotlin/io/sentry/compose/ComposeIntegrationTests.kt similarity index 100% rename from sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/ComposeIntegrationTests.kt rename to sentry-compose/src/androidHostTest/kotlin/io/sentry/compose/ComposeIntegrationTests.kt diff --git a/sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/SentryLifecycleObserverTest.kt b/sentry-compose/src/androidHostTest/kotlin/io/sentry/compose/SentryLifecycleObserverTest.kt similarity index 100% rename from sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/SentryLifecycleObserverTest.kt rename to sentry-compose/src/androidHostTest/kotlin/io/sentry/compose/SentryLifecycleObserverTest.kt diff --git a/sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/SentryModifierComposeTest.kt b/sentry-compose/src/androidHostTest/kotlin/io/sentry/compose/SentryModifierComposeTest.kt similarity index 100% rename from sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/SentryModifierComposeTest.kt rename to sentry-compose/src/androidHostTest/kotlin/io/sentry/compose/SentryModifierComposeTest.kt diff --git a/sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/SentryTracedTest.kt b/sentry-compose/src/androidHostTest/kotlin/io/sentry/compose/SentryTracedTest.kt similarity index 100% rename from sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/SentryTracedTest.kt rename to sentry-compose/src/androidHostTest/kotlin/io/sentry/compose/SentryTracedTest.kt diff --git a/sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/gestures/ComposeGestureTargetLocatorTest.kt b/sentry-compose/src/androidHostTest/kotlin/io/sentry/compose/gestures/ComposeGestureTargetLocatorTest.kt similarity index 100% rename from sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/gestures/ComposeGestureTargetLocatorTest.kt rename to sentry-compose/src/androidHostTest/kotlin/io/sentry/compose/gestures/ComposeGestureTargetLocatorTest.kt diff --git a/sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/viewhierarchy/ComposeViewHierarchyExporterTest.kt b/sentry-compose/src/androidHostTest/kotlin/io/sentry/compose/viewhierarchy/ComposeViewHierarchyExporterTest.kt similarity index 100% rename from sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/viewhierarchy/ComposeViewHierarchyExporterTest.kt rename to sentry-compose/src/androidHostTest/kotlin/io/sentry/compose/viewhierarchy/ComposeViewHierarchyExporterTest.kt diff --git a/sentry-compose/src/androidMain/kotlin/io/sentry/compose/SentryNavigationIntegration.kt b/sentry-compose/src/androidMain/kotlin/io/sentry/compose/SentryNavigationIntegration.kt index 07dd300075f..b83f91dbcd2 100644 --- a/sentry-compose/src/androidMain/kotlin/io/sentry/compose/SentryNavigationIntegration.kt +++ b/sentry-compose/src/androidMain/kotlin/io/sentry/compose/SentryNavigationIntegration.kt @@ -28,7 +28,7 @@ internal class SentryLifecycleObserver( private companion object { init { SentryIntegrationPackageStorage.getInstance() - .addPackage("maven:io.sentry:sentry-compose", BuildConfig.VERSION_NAME) + .addPackage("maven:io.sentry:sentry-compose", SENTRY_COMPOSE_VERSION_NAME) } } diff --git a/sentry-compose/src/androidMain/kotlin/io/sentry/compose/gestures/ComposeGestureTargetLocator.kt b/sentry-compose/src/androidMain/kotlin/io/sentry/compose/gestures/ComposeGestureTargetLocator.kt index ba011e455ab..b0148fb4f37 100644 --- a/sentry-compose/src/androidMain/kotlin/io/sentry/compose/gestures/ComposeGestureTargetLocator.kt +++ b/sentry-compose/src/androidMain/kotlin/io/sentry/compose/gestures/ComposeGestureTargetLocator.kt @@ -9,7 +9,7 @@ import androidx.compose.ui.node.Owner import androidx.compose.ui.semantics.SemanticsModifier import io.sentry.ILogger import io.sentry.SentryIntegrationPackageStorage -import io.sentry.compose.BuildConfig +import io.sentry.compose.SENTRY_COMPOSE_VERSION_NAME import io.sentry.compose.SentryComposeHelper import io.sentry.compose.boundsInWindow import io.sentry.internal.gestures.GestureTargetLocator @@ -25,7 +25,7 @@ public class ComposeGestureTargetLocator(private val logger: ILogger) : GestureT init { SentryIntegrationPackageStorage.getInstance() - .addPackage("maven:io.sentry:sentry-compose", BuildConfig.VERSION_NAME) + .addPackage("maven:io.sentry:sentry-compose", SENTRY_COMPOSE_VERSION_NAME) } override fun locate(root: Any?, x: Float, y: Float, targetType: UiElement.Type): UiElement? {