Skip to content

refactor(android): Convert sentry.gradle to Kotlin DSL (sentry.gradle.kts)#6119

Merged
antonis merged 14 commits into
mainfrom
antonis/convert-sentry-gradle-to-kts
May 28, 2026
Merged

refactor(android): Convert sentry.gradle to Kotlin DSL (sentry.gradle.kts)#6119
antonis merged 14 commits into
mainfrom
antonis/convert-sentry-gradle-to-kts

Conversation

@antonis
Copy link
Copy Markdown
Contributor

@antonis antonis commented May 8, 2026

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Converts sentry.gradle (Groovy) to sentry.gradle.kts (Kotlin DSL).

  • Rewrites the entire script in Kotlin, using typed data classes (BundleTaskArgs, ForceSourceMapResult, VariantInfo) instead of Groovy dynamic lists
  • Keeps sentry.gradle as a one-line shim forwarding to sentry.gradle.kts for backward compatibility with existing build.gradle references
  • Uses groovy.lang.Closure<Boolean> with doCall() for extra[...] properties to ensure proper Groovy interop from consuming build.gradle files
  • Uses reflection-based AGP access (java.lang.reflect.Proxy) wrapped in try/catch for resilience across AGP versions
  • Uses DefaultGroovyMethods.getProperties() for task property access (Kotlin DSL can't resolve .properties directly on Gradle tasks)
  • Replaces Groovy's List.execute() with ProcessBuilder, with redirectErrorStream(true) and stdout read before waitFor() to prevent deadlocks
  • Handles both File and Directory types for the root property (varies across RN/AGP versions)
  • Uses Character.toLowerCase()/Character.toUpperCase() and String.contains(ignoreCase) for cross-version Kotlin compat (works on both Gradle 7.5/RN 0.71 and Gradle 9.3/RN 0.85+)
  • Preserves forced sourcemap output injection when --sourcemap-output isn't explicitly configured
  • Removes extractBundleTaskArgumentsLegacy (RN < 0.71 dead code — minimum supported is 0.71+)
  • Expo plugin auto-migrates old sentry.gradle references to sentry.gradle.kts on upgrade
  • Updates all build.gradle references across samples, e2e tests, perf tests, and patch scripts

💡 Motivation and Context

Closes #2327

Gradle's Kotlin DSL provides type safety, better IDE support, and is the recommended script language going forward. The Groovy .gradle format is in maintenance mode. This aligns with the sentry-java/android SDK which already uses Kotlin DSL.

💚 How did you test it?

  • Expo plugin tests pass (6 tests in modifyAppBuildGradle, including new migration test)
  • Native check tests pass (14 tests in sentryExpoNativeCheck)
  • Local Gradle build validation with JDK 17 + Gradle 9.3.1 (sample app)
  • CI: RN 0.71 build passes (validates older Kotlin/Gradle compat)
  • CI: codegen, sample app builds, e2e tests
  • Checked the full blame history of sentry.gradle for possible regressions

📝 Checklist

  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • All tests passing
  • No breaking changes

🔮 Next steps

  • Update sentry-wizard to reference sentry.gradle.kts
  • Consider follow-up: matrix CI testing across AGP × Gradle × RN versions

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • refactor(android): Convert sentry.gradle to Kotlin DSL (sentry.gradle.kts) by antonis in #6119

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Warnings
⚠️

⚠️ Auth token handling changes detected

This PR modifies code related to Sentry auth token handling. Please ensure no auth tokens are accidentally exposed or mishandled. See GHSA-68c2-4mpx-qh95 for context.

Files with auth token changes:

  • packages/core/sentry.gradle.kts

Generated by 🚫 dangerJS against b30a6fb

@antonis antonis added the ready-to-merge Triggers the full CI test suite label May 8, 2026
Comment thread packages/core/sentry.gradle.kts Outdated
Comment thread packages/core/sentry.gradle.kts
Comment thread packages/core/sentry.gradle.kts Outdated
Comment thread packages/core/sentry.gradle.kts Outdated
Comment thread packages/core/sentry.gradle.kts Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

iOS (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 3837.30 ms 1214.39 ms -2622.92 ms
Size 5.15 MiB 6.69 MiB 1.54 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
0b5120f+dirty 3838.39 ms 1232.91 ms -2605.48 ms
4e0ba9c+dirty 3839.22 ms 1221.06 ms -2618.16 ms
0d9949d+dirty 1211.38 ms 1219.67 ms 8.29 ms
bc0d8cf+dirty 3830.33 ms 1220.52 ms -2609.81 ms
c151573+dirty 3841.06 ms 1232.13 ms -2608.93 ms
7d6fd3a+dirty 1223.29 ms 1229.57 ms 6.28 ms
a3265b6+dirty 3826.31 ms 1207.87 ms -2618.44 ms
5c1e987+dirty 1204.30 ms 1222.15 ms 17.85 ms
5125c43+dirty 3846.45 ms 1221.12 ms -2625.32 ms
5569641+dirty 3839.22 ms 1231.30 ms -2607.91 ms

App size

Revision Plain With Sentry Diff
0b5120f+dirty 5.15 MiB 6.68 MiB 1.53 MiB
4e0ba9c+dirty 5.15 MiB 6.67 MiB 1.51 MiB
0d9949d+dirty 3.38 MiB 4.76 MiB 1.38 MiB
bc0d8cf+dirty 5.15 MiB 6.67 MiB 1.51 MiB
c151573+dirty 5.15 MiB 6.68 MiB 1.53 MiB
7d6fd3a+dirty 3.38 MiB 4.77 MiB 1.39 MiB
a3265b6+dirty 5.15 MiB 6.68 MiB 1.53 MiB
5c1e987+dirty 3.38 MiB 4.73 MiB 1.35 MiB
5125c43+dirty 5.15 MiB 6.68 MiB 1.53 MiB
5569641+dirty 5.15 MiB 6.67 MiB 1.51 MiB

Previous results on branch: antonis/convert-sentry-gradle-to-kts

Startup times

Revision Plain With Sentry Diff
ab174a6+dirty 3844.81 ms 1231.45 ms -2613.35 ms
825a670+dirty 3851.48 ms 1228.34 ms -2623.14 ms

App size

Revision Plain With Sentry Diff
ab174a6+dirty 5.15 MiB 6.68 MiB 1.53 MiB
825a670+dirty 5.15 MiB 6.68 MiB 1.53 MiB

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

iOS (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 3846.46 ms 1231.45 ms -2615.00 ms
Size 5.15 MiB 6.69 MiB 1.54 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
0b5120f+dirty 3843.24 ms 1223.00 ms -2620.24 ms
4e0ba9c+dirty 3856.39 ms 1234.44 ms -2621.95 ms
0d9949d+dirty 1203.94 ms 1202.27 ms -1.67 ms
bc0d8cf+dirty 3834.64 ms 1223.91 ms -2610.73 ms
c151573+dirty 3835.64 ms 1216.10 ms -2619.53 ms
7d6fd3a+dirty 1210.89 ms 1217.63 ms 6.74 ms
a3265b6+dirty 3844.26 ms 1235.60 ms -2608.66 ms
5c1e987+dirty 1208.43 ms 1220.72 ms 12.29 ms
5125c43+dirty 3827.94 ms 1208.79 ms -2619.15 ms
5569641+dirty 3824.35 ms 1210.78 ms -2613.57 ms

App size

Revision Plain With Sentry Diff
0b5120f+dirty 5.15 MiB 6.68 MiB 1.53 MiB
4e0ba9c+dirty 5.15 MiB 6.67 MiB 1.51 MiB
0d9949d+dirty 3.38 MiB 4.76 MiB 1.38 MiB
bc0d8cf+dirty 5.15 MiB 6.67 MiB 1.51 MiB
c151573+dirty 5.15 MiB 6.68 MiB 1.53 MiB
7d6fd3a+dirty 3.38 MiB 4.77 MiB 1.39 MiB
a3265b6+dirty 5.15 MiB 6.68 MiB 1.53 MiB
5c1e987+dirty 3.38 MiB 4.73 MiB 1.35 MiB
5125c43+dirty 5.15 MiB 6.68 MiB 1.53 MiB
5569641+dirty 5.15 MiB 6.67 MiB 1.51 MiB

Previous results on branch: antonis/convert-sentry-gradle-to-kts

Startup times

Revision Plain With Sentry Diff
ab174a6+dirty 3829.17 ms 1210.90 ms -2618.27 ms
825a670+dirty 3851.98 ms 1228.43 ms -2623.55 ms

App size

Revision Plain With Sentry Diff
ab174a6+dirty 5.15 MiB 6.68 MiB 1.53 MiB
825a670+dirty 5.15 MiB 6.68 MiB 1.53 MiB

@antonis antonis force-pushed the antonis/convert-sentry-gradle-to-kts branch from 64495fd to b1ed616 Compare May 13, 2026 12:10
Comment thread packages/core/sentry.gradle.kts
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 13, 2026

Android (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 428.37 ms 480.16 ms 51.79 ms
Size 48.30 MiB 53.58 MiB 5.28 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
8929511+dirty 405.33 ms 452.16 ms 46.83 ms
5569641+dirty 406.43 ms 428.51 ms 22.08 ms
7ac3378+dirty 404.78 ms 439.84 ms 35.06 ms
7d6fd3a+dirty 403.02 ms 422.56 ms 19.54 ms
23598c3+dirty 414.12 ms 426.24 ms 12.12 ms
3ce5254+dirty 410.57 ms 448.48 ms 37.91 ms
ef27341+dirty 412.94 ms 443.98 ms 31.04 ms
44c8b3f+dirty 414.20 ms 457.28 ms 43.08 ms
853723c+dirty 405.54 ms 440.08 ms 34.54 ms
3b6e9f9+dirty 442.70 ms 486.44 ms 43.74 ms

App size

Revision Plain With Sentry Diff
8929511+dirty 43.75 MiB 48.16 MiB 4.41 MiB
5569641+dirty 48.30 MiB 53.48 MiB 5.18 MiB
7ac3378+dirty 43.75 MiB 48.13 MiB 4.37 MiB
7d6fd3a+dirty 43.75 MiB 48.14 MiB 4.39 MiB
23598c3+dirty 43.75 MiB 48.16 MiB 4.41 MiB
3ce5254+dirty 43.75 MiB 48.12 MiB 4.37 MiB
ef27341+dirty 48.30 MiB 53.54 MiB 5.24 MiB
44c8b3f+dirty 48.30 MiB 53.46 MiB 5.15 MiB
853723c+dirty 48.30 MiB 53.58 MiB 5.28 MiB
3b6e9f9+dirty 48.30 MiB 53.54 MiB 5.23 MiB

Previous results on branch: antonis/convert-sentry-gradle-to-kts

Startup times

Revision Plain With Sentry Diff
ab174a6+dirty 426.60 ms 482.98 ms 56.38 ms
825a670+dirty 423.40 ms 457.80 ms 34.40 ms

App size

Revision Plain With Sentry Diff
ab174a6+dirty 48.30 MiB 53.54 MiB 5.23 MiB
825a670+dirty 48.30 MiB 53.54 MiB 5.23 MiB

@sentry
Copy link
Copy Markdown

sentry Bot commented May 13, 2026

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
Sentry RN io.sentry.reactnative.sample 8.13.0 (90) Release

⚙️ sentry-react-native Build Distribution Settings

Comment thread packages/core/sentry.gradle
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 1118790. Configure here.

@antonis antonis force-pushed the antonis/convert-sentry-gradle-to-kts branch from 7f5736c to e850959 Compare May 13, 2026 16:23
….kts)

Convert the Groovy-based sentry.gradle script to Kotlin DSL for better
type safety and IDE support. The original sentry.gradle is kept as a
one-line shim that forwards to sentry.gradle.kts for backward
compatibility with existing app/build.gradle references.

Key changes:
- Full Kotlin DSL rewrite with proper type annotations
- Groovy interop via DefaultGroovyMethods and groovy.lang.Closure wrappers
- AGP reflection wrapped in try/catch for resilience
- Cross-version Kotlin compat using Java Character API
- ProcessBuilder deadlock prevention (read stdout before waitFor)
- Handle both File and Directory types for root property
- Expo plugin auto-migrates old sentry.gradle refs to sentry.gradle.kts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@antonis antonis force-pushed the antonis/convert-sentry-gradle-to-kts branch from e850959 to 4735111 Compare May 13, 2026 16:30
Comment thread packages/core/sentry.gradle
Comment thread packages/core/plugin/src/withSentryAndroid.ts Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 4735111. Configure here.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 13, 2026

Android (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 412.73 ms 466.91 ms 54.19 ms
Size 48.30 MiB 53.58 MiB 5.28 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
4953e94+dirty 398.80 ms 431.81 ms 33.01 ms
5569641+dirty 465.92 ms 532.22 ms 66.30 ms
100ce80+dirty 463.28 ms 532.10 ms 68.82 ms
ef27341+dirty 519.02 ms 553.42 ms 34.40 ms
8929511+dirty 469.49 ms 502.65 ms 33.16 ms
853723c+dirty 415.82 ms 460.94 ms 45.12 ms
3b6e9f9+dirty 442.39 ms 486.44 ms 44.05 ms
44c8b3f+dirty 492.13 ms 563.47 ms 71.34 ms
d038a14+dirty 405.08 ms 444.36 ms 39.28 ms
c151573+dirty 485.39 ms 495.18 ms 9.79 ms

App size

Revision Plain With Sentry Diff
4953e94+dirty 43.94 MiB 48.94 MiB 5.00 MiB
5569641+dirty 48.30 MiB 53.48 MiB 5.18 MiB
100ce80+dirty 48.30 MiB 53.46 MiB 5.15 MiB
ef27341+dirty 48.30 MiB 53.54 MiB 5.24 MiB
8929511+dirty 43.94 MiB 49.02 MiB 5.08 MiB
853723c+dirty 48.30 MiB 53.58 MiB 5.28 MiB
3b6e9f9+dirty 48.30 MiB 53.54 MiB 5.23 MiB
44c8b3f+dirty 48.30 MiB 53.46 MiB 5.15 MiB
d038a14+dirty 48.30 MiB 53.49 MiB 5.19 MiB
c151573+dirty 48.30 MiB 53.54 MiB 5.24 MiB

Previous results on branch: antonis/convert-sentry-gradle-to-kts

Startup times

Revision Plain With Sentry Diff
ab174a6+dirty 421.98 ms 488.12 ms 66.14 ms
825a670+dirty 411.58 ms 485.61 ms 74.03 ms

App size

Revision Plain With Sentry Diff
ab174a6+dirty 48.30 MiB 53.54 MiB 5.23 MiB
825a670+dirty 48.30 MiB 53.54 MiB 5.23 MiB

@antonis antonis requested a review from romtsn May 13, 2026 17:35
@antonis antonis marked this pull request as ready for review May 13, 2026 17:35
@lucas-zimerman
Copy link
Copy Markdown
Collaborator

Might be worth adding a changelog for it. Also I am wondering if we shouldn't do this on v9 instead of main

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread packages/core/sentry.gradle.kts Outdated
@antonis
Copy link
Copy Markdown
Contributor Author

antonis commented May 15, 2026

Might be worth adding a changelog for it.

Good point @lucas-zimerman 👍 I've added a note with 94b1795

Also I am wondering if we shouldn't do this on v9 instead of main

I was thinking that this is an internal change that should not affect any public api or convention. Do you have a specific scenario in mind that may cause a breakage?

Comment thread packages/core/sentry.gradle.kts Outdated
Comment thread packages/core/sentry.gradle.kts
…radle plugin

The lookbehind ensures the regex only matches sentry.gradle preceded by
a quote or slash character, avoiding false positives on package names.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@antonis
Copy link
Copy Markdown
Contributor Author

antonis commented May 15, 2026

Good catch by Warden — fixed in c3effa6. The migration regex now uses a lookbehind (?<=[/"']) to only match sentry.gradle when preceded by a quote or slash, preventing false positives on package names like io.sentry.android.gradle. Added a test case to cover this scenario.

Comment thread packages/core/sentry.gradle.kts
Comment thread packages/core/sentry.gradle.kts
Comment thread packages/core/sentry.gradle.kts
@antonis antonis marked this pull request as draft May 15, 2026 12:19
antonis and others added 2 commits May 15, 2026 14:30
… smart-cast

- Re-add extractBundleTaskArgumentsLegacy for projects on RN 0.65-0.70
  that lack Provider-based bundle task properties
- Assign reactRoot to immutable val after null check for clean Kotlin
  smart-casting in task lambdas

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract args.bundleOutput into local val to avoid smart-cast failure
on older Kotlin compilers (Gradle 7.5.1 / RN 0.71).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread packages/core/sentry.gradle.kts
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3d46737. Configure here.

Comment thread packages/core/sentry.gradle.kts
@antonis antonis marked this pull request as ready for review May 15, 2026 12:59
Comment thread packages/core/sentry.gradle.kts
Comment thread packages/core/sentry.gradle.kts
@lucas-zimerman
Copy link
Copy Markdown
Collaborator

So far the PR looks good! but I'd like an extra review from @romtsn before merging it.

@antonis antonis removed the ready-to-merge Triggers the full CI test suite label May 21, 2026
Comment thread packages/core/sentry.gradle.kts
Comment thread packages/core/sentry.gradle.kts
Copy link
Copy Markdown
Member

@romtsn romtsn left a comment

Choose a reason for hiding this comment

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

LGTM, sorry it took longer

…y-gradle-to-kts

# Conflicts:
#	CHANGELOG.md
#	packages/core/plugin/src/withSentryAndroid.ts
@antonis antonis added the ready-to-merge Triggers the full CI test suite label May 28, 2026
Comment thread packages/core/plugin/src/withSentryAndroid.ts
Comment thread packages/core/sentry.gradle.kts
Comment thread packages/core/plugin/src/withSentryAndroid.ts
…ride support

- Functions now read from extra at call time instead of capturing local
  vals, so Expo plugin's disableAutoUpload override takes effect
- Migration path recurses with disableAutoUpload to apply in one pass
- Add test for migration + disableAutoUpload combined
- Add @Suppress("UNCHECKED_CAST") to closure cast helpers

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread packages/core/sentry.gradle.kts
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b30a6fb. Configure here.

Comment thread packages/core/sentry.gradle.kts
Comment thread packages/core/sentry.gradle.kts
@antonis antonis merged commit 5257d80 into main May 28, 2026
87 checks passed
@antonis antonis deleted the antonis/convert-sentry-gradle-to-kts branch May 28, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Triggers the full CI test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert sentry.gradle to Kotlin and add Matrix testing (AGP vs Gradle vs RN)

3 participants