Skip to content

Commit 973f7d0

Browse files
runningcodeclaude
andcommitted
fix(snapshot): Make sentry snapshot output directory variant-aware
Use build/sentry-snapshots/{variant}/images/ instead of a shared directory so that different build variants don't overwrite each other. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e2af774 commit 973f7d0

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

plugin-build/src/main/kotlin/io/sentry/android/gradle/AndroidComponentsConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ private fun ApplicationVariant.configureSnapshotsTasks(
485485
taskSuffix = name.capitalized,
486486
)
487487
uploadTask.configure { task ->
488-
task.snapshotsPath.set(project.layout.buildDirectory.dir("sentry-snapshots/images"))
488+
task.snapshotsPath.set(project.layout.buildDirectory.dir("sentry-snapshots/${name}/images"))
489489
}
490490
}
491491

plugin-build/src/main/kotlin/io/sentry/android/gradle/snapshot/SentrySnapshotPlugin.kt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,25 @@ class SentrySnapshotPlugin : Plugin<Project> {
3131
val androidComponents =
3232
project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java)
3333

34-
val sentrySnapshotRootDir = project.layout.buildDirectory.dir("sentry-snapshots")
35-
project.tasks.withType(Test::class.java).configureEach { testTask ->
36-
testTask.systemProperty(
37-
"sentry.snapshot.output",
38-
sentrySnapshotRootDir.get().asFile.absolutePath,
39-
)
40-
testTask.systemProperty("paparazzi.test.record", "true")
41-
testTask.doFirst {
42-
val imagesDir = File(sentrySnapshotRootDir.get().asFile, "images")
43-
if (imagesDir.exists()) {
44-
imagesDir.deleteRecursively()
34+
androidComponents.onVariants { variant ->
35+
val variantName = variant.name
36+
val sentrySnapshotRootDir = project.layout.buildDirectory.dir("sentry-snapshots/$variantName")
37+
val testTaskName = "test${variantName.replaceFirstChar { it.uppercase() }}UnitTest"
38+
project.tasks.matching { it.name == testTaskName }.configureEach { task ->
39+
val testTask = task as Test
40+
testTask.systemProperty(
41+
"sentry.snapshot.output",
42+
sentrySnapshotRootDir.get().asFile.absolutePath,
43+
)
44+
testTask.systemProperty("paparazzi.test.record", "true")
45+
testTask.doFirst {
46+
val imagesDir = File(sentrySnapshotRootDir.get().asFile, "images")
47+
if (imagesDir.exists()) {
48+
imagesDir.deleteRecursively()
49+
}
4550
}
4651
}
47-
}
4852

49-
androidComponents.onVariants { variant ->
5053
val generateTask = GenerateSnapshotTestsTask.register(project, extension, android, variant)
5154
if (AgpVersions.isAGP90(AgpVersions.CURRENT)) {
5255
// Right now it seems we only have HostTestBuilder.UNIT_TEST_TYPE as the key but we are

0 commit comments

Comments
 (0)