Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 6.4.0-alpha.5

### Internal Changes 🔧

#### Deps

- Update CLI to v3.3.5 by @github-actions in [#1132](https://github.com/getsentry/sentry-android-gradle-plugin/pull/1132)
- Update CLI to v3.3.4 by @github-actions in [#1122](https://github.com/getsentry/sentry-android-gradle-plugin/pull/1122)

## 6.4.0-alpha.4

### Internal Changes 🔧
Expand Down
15 changes: 0 additions & 15 deletions plugin-build/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ gradlePlugin {
id = "io.sentry.jvm.gradle"
implementationClass = "io.sentry.jvm.gradle.SentryJvmPlugin"
}
register("sentrySnapshotPlugin") {
id = "io.sentry.android.snapshot"
implementationClass = "io.sentry.android.gradle.snapshot.SentrySnapshotPlugin"
}
Comment thread
cursor[bot] marked this conversation as resolved.
register("sentrySnapshotMetadataPlugin") {
id = "io.sentry.android.snapshot.metadata"
implementationClass =
Expand Down Expand Up @@ -205,9 +201,6 @@ distributions {
create("sentryJvmPluginMarker") {
contents { from("build${sep}publications${sep}sentryJvmPluginPluginMarkerMaven") }
}
create("sentrySnapshotPluginMarker") {
contents { from("build${sep}publications${sep}sentrySnapshotPluginPluginMarkerMaven") }
}
create("sentrySnapshotMetadataPluginMarker") {
contents { from("build${sep}publications${sep}sentrySnapshotMetadataPluginPluginMarkerMaven") }
}
Expand Down Expand Up @@ -257,14 +250,6 @@ tasks.named("sentryPluginMarkerDistZip").configure {
dependsOn("generatePomFileForSentryPluginPluginMarkerMavenPublication")
}

tasks.named("sentrySnapshotPluginMarkerDistTar").configure {
dependsOn("generatePomFileForSentrySnapshotPluginPluginMarkerMavenPublication")
}

tasks.named("sentrySnapshotPluginMarkerDistZip").configure {
dependsOn("generatePomFileForSentrySnapshotPluginPluginMarkerMavenPublication")
}

tasks.named("sentrySnapshotMetadataPluginMarkerDistTar").configure {
dependsOn("generatePomFileForSentrySnapshotMetadataPluginPluginMarkerMavenPublication")
}
Expand Down
2 changes: 1 addition & 1 deletion plugin-build/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ org.gradle.parallel=true

name = sentry-android-gradle-plugin
group = io.sentry
version = 6.4.0-alpha.4
version = 6.4.0-alpha.5
sdk_version = 8.37.1

# publication pom properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import com.android.build.api.instrumentation.InstrumentationParameters
import com.android.build.api.instrumentation.InstrumentationScope
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.android.build.api.variant.ApplicationVariant
import com.android.build.api.variant.HostTestBuilder.Companion.UNIT_TEST_TYPE
import com.android.build.api.variant.Variant
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.internal.utils.setDisallowChanges
import io.sentry.android.gradle.SentryPlugin.Companion.sep
import io.sentry.android.gradle.SentryPropertiesFileProvider.getPropertiesFilePath
Expand All @@ -20,6 +22,7 @@ import io.sentry.android.gradle.SentryTasksProvider.getMappingFileProvider
import io.sentry.android.gradle.extensions.SentryPluginExtension
import io.sentry.android.gradle.instrumentation.SpanAddingClassVisitorFactory
import io.sentry.android.gradle.services.SentryModulesService
import io.sentry.android.gradle.snapshot.GenerateSnapshotTestsTask
import io.sentry.android.gradle.sourcecontext.OutputPaths
import io.sentry.android.gradle.sourcecontext.SourceContext
import io.sentry.android.gradle.tasks.GenerateDistributionPropertiesTask
Expand All @@ -46,6 +49,7 @@ import org.gradle.api.file.Directory
import org.gradle.api.provider.Provider
import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.testing.Test
import org.gradle.internal.build.event.BuildEventListenerRegistryInternal

fun ApplicationAndroidComponentsExtension.configure(
Expand Down Expand Up @@ -78,7 +82,9 @@ fun ApplicationAndroidComponentsExtension.configure(
}
}

variant.configureSnapshotsTasks(project, extension, cliExecutable, sentryOrg, sentryProject)
if (extension.snapshots.enabled.get()) {
variant.configureSnapshotsTasks(project, extension, cliExecutable, sentryOrg, sentryProject)
}
Comment thread
runningcode marked this conversation as resolved.

if (isVariantAllowed(extension, variant.name, variant.flavorName, variant.buildType)) {
val paths = OutputPaths(project, variant.name)
Expand Down Expand Up @@ -461,21 +467,74 @@ private fun ApplicationVariant.configureSnapshotsTasks(
cliExecutable: Provider<String>,
sentryOrg: String?,
sentryProject: String?,
): TaskProvider<SentryUploadSnapshotsTask> {
) {
val variant = AndroidVariant74(this)
val sentryProps = getPropertiesFilePath(project, variant)
val taskSuffix = name.capitalized

return SentryUploadSnapshotsTask.register(
project = project,
extension = extension,
sentryTelemetryProvider = null,
cliExecutable = cliExecutable,
sentryOrgOverride = sentryOrg,
sentryProjectOverride = sentryProject,
applicationId = applicationId,
sentryProperties = sentryProps,
taskSuffix = name.capitalized,
)
// Register the upload task
val uploadTask =
SentryUploadSnapshotsTask.register(
project = project,
extension = extension,
sentryTelemetryProvider = null,
cliExecutable = cliExecutable,
sentryOrgOverride = sentryOrg,
sentryProjectOverride = sentryProject,
applicationId = applicationId,
sentryProperties = sentryProps,
taskSuffix = taskSuffix,
)
Comment thread
sentry[bot] marked this conversation as resolved.

// Wire Paparazzi test generation and upload task when the Paparazzi plugin is applied
project.pluginManager.withPlugin("app.cash.paparazzi") {
val android = project.extensions.getByType(BaseExtension::class.java)

project.dependencies.add(
"testImplementation",
"io.github.sergio-sastre.ComposablePreviewScanner:android:0.8.1",
)

val generateTask =
GenerateSnapshotTestsTask.register(
project,
extension.snapshots,
android,
this@configureSnapshotsTasks,
)

if (AgpVersions.isAGP90(AgpVersions.CURRENT)) {
hostTests[UNIT_TEST_TYPE]?.apply {
sources.java?.addGeneratedSourceDirectory(
generateTask,
GenerateSnapshotTestsTask::outputDir,
)
}
} else {
@Suppress("DEPRECATION_ERROR")
unitTest?.apply {
sources.java?.addGeneratedSourceDirectory(
generateTask,
GenerateSnapshotTestsTask::outputDir,
)
}
}

project.afterEvaluate {
// Not all variants have unit test tasks (e.g. users can disable them),
Comment on lines +523 to +524
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The SentryUploadSnapshotsTask is registered unconditionally but its required snapshotsPath property is not set if the Paparazzi plugin is missing or if unit tests are disabled for a variant, causing a build failure.
Severity: HIGH

Suggested Fix

Move the registration of SentryUploadSnapshotsTask inside the project.pluginManager.withPlugin("app.cash.paparazzi") block. This ensures the task is only created when its required snapshotsPath property can be correctly configured, preventing build failures when Paparazzi is not in use.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location:
plugin-build/src/main/kotlin/io/sentry/android/gradle/AndroidComponentsConfig.kt#L523-L524

Potential issue: The `SentryUploadSnapshotsTask` is registered if
`extension.snapshots.enabled` is true. However, its required `snapshotsPath` property is
only configured under specific conditions. This leads to build failures in two
scenarios: 1) When the Paparazzi plugin is not applied, the configuration block is
skipped, leaving `snapshotsPath` unassigned. 2) When the Paparazzi plugin is applied but
unit tests are disabled for a specific build variant (e.g., `release`), an early return
in an `afterEvaluate` block prevents `snapshotsPath` from being set for that variant's
task. In both cases, Gradle's task validation fails because a required property is
missing.

// so skip wiring if the task doesn't exist.
val testTaskName = "test${taskSuffix}UnitTest"
if (testTaskName !in project.tasks.names) return@afterEvaluate

val testTask = project.tasks.named(testTaskName, Test::class.java)
uploadTask.configure { task ->
task.dependsOn("recordPaparazzi$taskSuffix")
Comment thread
sentry[bot] marked this conversation as resolved.
task.snapshotsPath.fileProvider(
testTask.map { it.outputs.files.files.first { file -> file.name == "snapshots" } }
)
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ abstract class SentryPluginExtension @Inject constructor(project: Project) {
vcsInfoAction.execute(vcsInfo)
}

val snapshots: SnapshotsExtension = objects.newInstance(SnapshotsExtension::class.java)

@Experimental
fun snapshots(snapshotsAction: Action<SnapshotsExtension>) {
snapshotsAction.execute(snapshots)
}

/**
* Disables or enables the reporting of dependencies metadata for Sentry. If enabled the plugin
* will collect external dependencies and will take care of uploading them to Sentry as part of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package io.sentry.android.gradle.snapshot
package io.sentry.android.gradle.extensions

import javax.inject.Inject
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.jetbrains.annotations.ApiStatus

/**
* Experimental extension for configuring Compose @Preview snapshot testing. This API is subject to
* change and will eventually be merged into the main `sentry` extension.
*/
@ApiStatus.Experimental
abstract class SentrySnapshotExtension(objects: ObjectFactory) {
open class SnapshotsExtension @Inject constructor(objects: ObjectFactory) {

val enabled: Property<Boolean> = objects.property(Boolean::class.java).convention(false)

val includePrivatePreviews: Property<Boolean> =
objects.property(Boolean::class.java).convention(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.sentry.android.gradle.snapshot
import com.android.build.api.variant.ApplicationVariant
import com.android.build.gradle.BaseExtension
import io.sentry.android.gradle.SentryTasksProvider.capitalized
import io.sentry.android.gradle.extensions.SnapshotsExtension
import java.io.File
import org.gradle.api.DefaultTask
import org.gradle.api.Project
Expand Down Expand Up @@ -58,24 +59,25 @@ abstract class GenerateSnapshotTestsTask : DefaultTask() {

fun register(
project: Project,
extension: SentrySnapshotExtension,
extension: SnapshotsExtension,
android: BaseExtension,
variant: ApplicationVariant,
): TaskProvider<GenerateSnapshotTestsTask> {
return project.tasks.register(
"generateSentrySnapshotTests${variant.name.capitalized}",
"sentryGenerateSnapshotsTests${variant.name.capitalized}",
GenerateSnapshotTestsTask::class.java,
) { task ->
task.includePrivatePreviews.set(extension.includePrivatePreviews)
task.theme.set(extension.theme)
// Fall back to the Android namespace when the user doesn't configure packageTrees
// TODO do we actually need this?
task.packageTrees.set(
extension.packageTrees.map { packages ->
packages.ifEmpty { listOf(android.namespace!!) }
}
)
task.outputDir.set(
project.layout.buildDirectory.dir("generated/sentry/snapshotTests/${variant.name}")
project.layout.buildDirectory.dir("generated/sentry/snapshotsTests/${variant.name}")
)
}
}
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion sentry-kotlin-compiler-plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.parallel=true

GROUP = io.sentry
POM_ARTIFACT_ID = sentry-kotlin-compiler-plugin
VERSION_NAME = 6.4.0-alpha.4
VERSION_NAME = 6.4.0-alpha.5

# publication pom properties
POM_NAME=Sentry Kotlin Compiler Plugin
Expand Down
Loading