Skip to content

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

Open
antonis wants to merge 1 commit into
mainfrom
antonis/convert-sentry-gradle-to-kts
Open

refactor(android): Convert sentry.gradle to Kotlin DSL (sentry.gradle.kts)#6119
antonis wants to merge 1 commit 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
  • Filter ExceptionsManager.reportException duplicates in app-start init by alwx in #6145
  • chore(deps): update JavaScript SDK to v10.53.1 by github-actions in #6139
  • feat(core): Enable autoInjectSentryLabel by default in Metro config by antonis in #6141
  • feat(core): Respect Mask boundaries when reading sentry-label by antonis in #6142
  • fix(android): Handle boolean values in JSON options converter by antonis in #6130
  • Multi-instance <TimeToInitialDisplay> / <TimeToFullDisplay> coordination; a multi-signal TTID/TTFD system by alwx in #6090
  • chore(deps): update Bundler Plugins to v5.3.0 by github-actions in #6138
  • chore: Merge 8.11.1 back to main by antonis in #6135
  • chore: Update warning regarding iOS crash in sentry-cocoa 9.12.0 by antonis in #6136
  • chore(deps): update CLI to v3.4.2 by github-actions in #6129
  • chore(deps): bump getsentry/craft/.github/workflows/changelog-preview.yml from 2.26.2 to 2.26.3 by dependabot in #6126
  • chore(deps): bump getsentry/craft from 2.26.2 to 2.26.3 by dependabot in #6127
  • chore(deps): bump github/codeql-action from 4.35.3 to 4.35.4 by dependabot in #6128
  • feat(core): Extract text from children of touched components for breadcrumb labels by antonis in #6106
  • chore(deps): bump @babel/plugin-transform-modules-systemjs from 7.25.0 to 7.29.4 by dependabot in #6124
  • chore(deps): bump fast-uri from 3.0.1 to 3.1.2 by dependabot in #6121
  • chore(deps): bump fast-xml-builder from 1.1.5 to 1.2.0 by dependabot in #6120
  • chore(deps): bump socks to ^2.8.8 to fix ip-address vulnerability by antonis in #6117
  • chore(deps): bump uuid to ^13.0.1 to fix buffer bounds check vulnerability by antonis in #6118
  • test(replay): Add passthrough tests for device-state replay breadcrumbs by antonis in #6115
  • chore(deps): update JavaScript SDK to v10.52.0 by github-actions in #6108
  • chore(deps): bump basic-ftp from 5.3.0 to 5.3.1 by dependabot in #6111

🤖 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 4735111

@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 3853.30 ms 1232.94 ms -2620.37 ms
Size 5.15 MiB 6.68 MiB 1.53 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
bc0d8cf+dirty 3830.33 ms 1220.52 ms -2609.81 ms
7d6fd3a+dirty 1223.29 ms 1229.57 ms 6.28 ms
df5d108+dirty 1225.90 ms 1220.14 ms -5.76 ms
5fe1c6c+dirty 1220.79 ms 1217.63 ms -3.16 ms
4e0ba9c+dirty 3839.22 ms 1221.06 ms -2618.16 ms
2c735cc+dirty 1229.67 ms 1221.50 ms -8.17 ms
a50b33d+dirty 1197.74 ms 1197.17 ms -0.57 ms
3d377b5+dirty 1218.48 ms 1219.51 ms 1.03 ms
5569641+dirty 3839.22 ms 1231.30 ms -2607.91 ms
23598c3+dirty 1207.00 ms 1209.90 ms 2.90 ms

App size

Revision Plain With Sentry Diff
bc0d8cf+dirty 5.15 MiB 6.67 MiB 1.51 MiB
7d6fd3a+dirty 3.38 MiB 4.77 MiB 1.39 MiB
df5d108+dirty 3.38 MiB 4.73 MiB 1.35 MiB
5fe1c6c+dirty 3.38 MiB 4.77 MiB 1.39 MiB
4e0ba9c+dirty 5.15 MiB 6.67 MiB 1.51 MiB
2c735cc+dirty 3.38 MiB 4.74 MiB 1.35 MiB
a50b33d+dirty 3.38 MiB 4.73 MiB 1.35 MiB
3d377b5+dirty 3.38 MiB 4.76 MiB 1.38 MiB
5569641+dirty 5.15 MiB 6.67 MiB 1.51 MiB
23598c3+dirty 3.38 MiB 4.80 MiB 1.42 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 3841.07 ms 1232.87 ms -2608.20 ms
Size 5.15 MiB 6.68 MiB 1.53 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
d038a14+dirty 3831.11 ms 1216.30 ms -2614.81 ms
5569641+dirty 3824.35 ms 1210.78 ms -2613.57 ms
5a21b51+dirty 3837.87 ms 1223.47 ms -2614.40 ms
4b87b12+dirty 1199.49 ms 1199.78 ms 0.29 ms
f3215d3+dirty 3846.08 ms 1231.85 ms -2614.23 ms
7d6fd3a+dirty 1210.89 ms 1217.63 ms 6.74 ms
3d377b5+dirty 1201.55 ms 1201.80 ms 0.25 ms
23598c3+dirty 1223.59 ms 1229.13 ms 5.53 ms
4953e94+dirty 1217.41 ms 1223.53 ms 6.12 ms
04207c4+dirty 1228.55 ms 1226.04 ms -2.51 ms

App size

Revision Plain With Sentry Diff
d038a14+dirty 5.15 MiB 6.67 MiB 1.51 MiB
5569641+dirty 5.15 MiB 6.67 MiB 1.51 MiB
5a21b51+dirty 5.15 MiB 6.67 MiB 1.51 MiB
4b87b12+dirty 3.38 MiB 4.77 MiB 1.39 MiB
f3215d3+dirty 5.15 MiB 6.67 MiB 1.52 MiB
7d6fd3a+dirty 3.38 MiB 4.77 MiB 1.39 MiB
3d377b5+dirty 3.38 MiB 4.76 MiB 1.38 MiB
23598c3+dirty 3.38 MiB 4.80 MiB 1.42 MiB
4953e94+dirty 3.38 MiB 4.73 MiB 1.35 MiB
04207c4+dirty 3.38 MiB 4.76 MiB 1.38 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 398.60 ms 421.10 ms 22.50 ms
Size 48.30 MiB 53.54 MiB 5.23 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
3d377b5+dirty 406.18 ms 453.52 ms 47.34 ms
8929511+dirty 405.33 ms 452.16 ms 46.83 ms
100ce80+dirty 463.66 ms 539.56 ms 75.90 ms
3817909+dirty 406.67 ms 416.58 ms 9.91 ms
3b6e9f9+dirty 442.70 ms 486.44 ms 43.74 ms
4e0ba9c+dirty 452.84 ms 473.36 ms 20.52 ms
5fe1c6c+dirty 401.62 ms 445.28 ms 43.66 ms
44c8b3f+dirty 414.20 ms 457.28 ms 43.08 ms
890d145+dirty 504.54 ms 491.55 ms -12.99 ms
3ce5254+dirty 410.57 ms 448.48 ms 37.91 ms

App size

Revision Plain With Sentry Diff
3d377b5+dirty 43.75 MiB 48.14 MiB 4.39 MiB
8929511+dirty 43.75 MiB 48.16 MiB 4.41 MiB
100ce80+dirty 48.30 MiB 53.46 MiB 5.15 MiB
3817909+dirty 43.75 MiB 48.08 MiB 4.33 MiB
3b6e9f9+dirty 48.30 MiB 53.54 MiB 5.23 MiB
4e0ba9c+dirty 48.30 MiB 53.49 MiB 5.19 MiB
5fe1c6c+dirty 43.75 MiB 48.14 MiB 4.39 MiB
44c8b3f+dirty 48.30 MiB 53.46 MiB 5.15 MiB
890d145+dirty 43.75 MiB 48.14 MiB 4.39 MiB
3ce5254+dirty 43.75 MiB 48.12 MiB 4.37 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.11.1 (88) 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
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

Android (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 412.00 ms 451.84 ms 39.84 ms
Size 48.30 MiB 53.54 MiB 5.23 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
a736b76+dirty 405.78 ms 458.74 ms 52.96 ms
890d145+dirty 486.42 ms 514.85 ms 28.43 ms
5fe1c6c+dirty 365.84 ms 408.62 ms 42.78 ms
44c8b3f+dirty 492.13 ms 563.47 ms 71.34 ms
04207c4+dirty 395.40 ms 456.55 ms 61.15 ms
3b6e9f9+dirty 442.39 ms 486.44 ms 44.05 ms
4e0ba9c+dirty 421.39 ms 455.80 ms 34.41 ms
3817909+dirty 357.52 ms 391.52 ms 34.00 ms
bc0d8cf+dirty 407.66 ms 461.35 ms 53.69 ms
5569641+dirty 465.92 ms 532.22 ms 66.30 ms

App size

Revision Plain With Sentry Diff
a736b76+dirty 48.30 MiB 53.48 MiB 5.18 MiB
890d145+dirty 43.94 MiB 49.00 MiB 5.06 MiB
5fe1c6c+dirty 43.94 MiB 49.00 MiB 5.06 MiB
44c8b3f+dirty 48.30 MiB 53.46 MiB 5.15 MiB
04207c4+dirty 43.94 MiB 48.98 MiB 5.04 MiB
3b6e9f9+dirty 48.30 MiB 53.54 MiB 5.23 MiB
4e0ba9c+dirty 48.30 MiB 53.49 MiB 5.19 MiB
3817909+dirty 43.94 MiB 48.94 MiB 5.00 MiB
bc0d8cf+dirty 48.30 MiB 53.48 MiB 5.18 MiB
5569641+dirty 48.30 MiB 53.48 MiB 5.18 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
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)

1 participant