Summary
Add automated test coverage for the Android Gradle asset-generation logic in packages/core/sentry.gradle.kts — specifically the GenerateSentryOptionsTask introduced in #6751. Today this logic is only verified manually against the sample apps; there is no automated regression protection.
Background
#6751 replaced the old copySentryJsonConfiguration copy+cleanup tasks with a typed GenerateSentryOptionsTask that generates sentry.options.json into build/generated/sentry/options/ and registers it as a generated assets source. The task owns non-trivial logic:
- Plain copy of the source
sentry.options.json into the generated dir.
SENTRY_ENVIRONMENT / SENTRY_RELEASE / SENTRY_DIST override rewriting of the JSON keys.
- Invalid-JSON fallback (copy as-is with a warning).
- Missing-source handling (leave the output dir empty).
SENTRY_COPY_OPTIONS_FILE=false opt-out (clear the output, produce nothing).
Raised by automated review on #6751: no tests reference GenerateSentryOptionsTask / generateSentryOptions, whereas the parallel iOS path (sentry-xcode.sh) and the Metro serializer are covered.
Why this isn't a quick add
sentry.gradle.kts is a script plugin, applied by consumers via apply from: "…/sentry.gradle.kts". The task class is declared inside the script, so:
- It is not compiled into any module and cannot be
imported by a test.
- The existing JUnit tests (
packages/core/android/src/test/...) belong to the :sentry_react-native library module (io.sentry.react.*), a different compilation unit / classpath.
- There is no
buildSrc, no GradleTestKit harness, and no standalone Gradle-plugin module. buildSrc would not help — it lives on the library's build classpath, not the consumer app's build where the script executes.
So there is no seam to unit-test the task as-is. Two viable paths, both larger than the original fix:
Option A — GradleTestKit functional test
Add a test module with gradleTestKit(), a fixture Android app that apply froms the script, run generateSentryOptions, and assert the generated file + up-to-date/caching behavior.
- Cost: requires AGP + Android SDK on the test classpath (the script reflects against the AGP variant API and runs inside
com.android.application). New, slower, potentially flaky CI job.
- Upside: exercises the real wiring (generated-source registration,
merge*Assets ordering) end to end, not just the pure logic.
Option B — Extract to a binary plugin + ProjectBuilder unit test
Move the task into a real compiled Gradle plugin / module so it can be imported, then unit-test the action with org.gradle.testfixtures.ProjectBuilder (no AGP needed — it's a plain DefaultTask).
- Cost: converting the script plugin to a binary plugin changes how consumers apply the SDK (
apply plugin vs apply from) — a breaking integration change requiring a migration path.
- Upside: fast, isolated unit tests of the core logic; also a cleaner long-term architecture.
Cases to cover (whichever path)
Recommendation
Prefer Option A for behavioral fidelity if the CI cost is acceptable; otherwise Option B as part of a broader move to a binary Gradle plugin. Track the plugin-ification separately if chosen, since it carries a consumer-facing migration.
References
Summary
Add automated test coverage for the Android Gradle asset-generation logic in
packages/core/sentry.gradle.kts— specifically theGenerateSentryOptionsTaskintroduced in #6751. Today this logic is only verified manually against the sample apps; there is no automated regression protection.Background
#6751 replaced the old
copySentryJsonConfigurationcopy+cleanup tasks with a typedGenerateSentryOptionsTaskthat generatessentry.options.jsonintobuild/generated/sentry/options/and registers it as a generated assets source. The task owns non-trivial logic:sentry.options.jsoninto the generated dir.SENTRY_ENVIRONMENT/SENTRY_RELEASE/SENTRY_DISToverride rewriting of the JSON keys.SENTRY_COPY_OPTIONS_FILE=falseopt-out (clear the output, produce nothing).Raised by automated review on #6751: no tests reference
GenerateSentryOptionsTask/generateSentryOptions, whereas the parallel iOS path (sentry-xcode.sh) and the Metro serializer are covered.Why this isn't a quick add
sentry.gradle.ktsis a script plugin, applied by consumers viaapply from: "…/sentry.gradle.kts". The task class is declared inside the script, so:imported by a test.packages/core/android/src/test/...) belong to the:sentry_react-nativelibrary module (io.sentry.react.*), a different compilation unit / classpath.buildSrc, no GradleTestKit harness, and no standalone Gradle-plugin module.buildSrcwould not help — it lives on the library's build classpath, not the consumer app's build where the script executes.So there is no seam to unit-test the task as-is. Two viable paths, both larger than the original fix:
Option A — GradleTestKit functional test
Add a test module with
gradleTestKit(), a fixture Android app thatapply froms the script, rungenerateSentryOptions, and assert the generated file + up-to-date/caching behavior.com.android.application). New, slower, potentially flaky CI job.merge*Assetsordering) end to end, not just the pure logic.Option B — Extract to a binary plugin +
ProjectBuilderunit testMove the task into a real compiled Gradle plugin / module so it can be imported, then unit-test the action with
org.gradle.testfixtures.ProjectBuilder(no AGP needed — it's a plainDefaultTask).apply pluginvsapply from) — a breaking integration change requiring a migration path.Cases to cover (whichever path)
SENTRY_ENVIRONMENT/SENTRY_RELEASE/SENTRY_DISToverrides rewrite the corresponding keys.SENTRY_COPY_OPTIONS_FILE=false→ output cleared / nothing generated (and a stale prior output is removed).merge{Debug,Release}Assetsand packaged; second build isUP-TO-DATE; nothing written tosrc/main/assets.Recommendation
Prefer Option A for behavioral fidelity if the CI cost is acceptable; otherwise Option B as part of a broader move to a binary Gradle plugin. Track the plugin-ification separately if chosen, since it carries a consumer-facing migration.
References
packages/core/sentry.gradle.kts—GenerateSentryOptionsTask(task class + wiring)packages/core/android/src/test/java/io/sentry/react/— existing (library-module) JUnit tests