Skip to content

[Don't review]: Add settings plugin with settings-level extension#1178

Open
runningcode wants to merge 8 commits intomainfrom
no/settings-extension
Open

[Don't review]: Add settings plugin with settings-level extension#1178
runningcode wants to merge 8 commits intomainfrom
no/settings-extension

Conversation

@runningcode
Copy link
Copy Markdown
Contributor

@runningcode runningcode commented May 6, 2026

Summary

Adds a settings-level plugin (io.sentry.android.gradle.settings) so users can configure shared Sentry properties once in settings.gradle.kts instead of repeating them in every module.

  • Both settings and project plugins use the same SentryPluginExtension class (previously there was a separate SentrySettingsExtension with duplicated properties — this was possible because the extension only needed ObjectFactory, not Project)
  • The settings plugin passes its extension instance to project plugins via ExtraPropertiesExtension on the Gradle object (the only shared state between settings and project scopes)
  • Each module's project-level extension receives the settings values as Property.convention() defaults, so project-level sentry {} overrides still take precedence
  • The settings plugin auto-applies io.sentry.android.gradle to library and java-library modules
  • Fully backward compatible — without the settings plugin, existing behavior is unchanged

Follows the DRY Gradle Configuration Values pattern.

User experience

// settings.gradle.kts
plugins {
    id("io.sentry.android.gradle.settings") version "x.y.z"
}
sentry {
    org.set("my-org")
    projectName.set("my-project")
    authToken.set(System.getenv("SENTRY_AUTH_TOKEN"))
    includeSourceContext.set(true)
}

// app/build.gradle.kts — no need to repeat org/project/auth
plugins {
    id("com.android.application")
    id("io.sentry.android.gradle")
}
// Library modules automatically get the plugin applied

🤖 Generated with Claude Code

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Features

- Add settings plugin with settings-level extension ([#1178](https://github.com/getsentry/sentry-android-gradle-plugin/pull/1178))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against d543fa2

@runningcode runningcode marked this pull request as ready for review May 6, 2026 10:00
Comment thread plugin-build/src/main/kotlin/io/sentry/android/gradle/SentrySettingsPlugin.kt Outdated
Comment thread plugin-build/src/main/kotlin/io/sentry/android/gradle/SentrySettingsPlugin.kt Outdated
Comment thread plugin-build/src/main/kotlin/io/sentry/android/gradle/SentrySettingsPlugin.kt Outdated
Comment thread plugin-build/src/main/kotlin/io/sentry/android/gradle/SentrySettingsPlugin.kt Outdated
runningcode and others added 6 commits May 6, 2026 13:24
Add `io.sentry.android.gradle.settings` settings plugin that provides
a `SentrySettingsExtension` for configuring shared properties (org,
project, authToken, url, debug, telemetry, includeSourceContext,
autoInstallation) once in settings.gradle.kts. These values flow to
each module's project-level extension as conventions via
ExtraPropertiesExtension, following the pattern from
liutikas.net/2024/10/28/DRY-Gradle-Configuration-Values.html.

The settings plugin also auto-applies `io.sentry.android.gradle` to
library and java-library modules, preparing for future multi-module
features (source context, snapshots).

Project-level `sentry {}` overrides still take precedence. Without the
settings plugin, existing behavior is unchanged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
SentryPluginExtension requires Project in its constructor, which
is unavailable during settings evaluation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
SentryPluginExtension only needed Project to get ObjectFactory, so
inject ObjectFactory directly instead. This lets both the settings
and project plugins use the same extension class, eliminating
SentrySettingsExtension and the duplicated property declarations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Android library modules now get auto-install dependencies via
  SentryPlugin's new withPlugin("com.android.library") block
- Java library modules now get the JVM plugin applied instead of the
  Android plugin, giving them source context + auto-install
- SentryJvmPlugin reads settings extension defaults
- Warning is suppressed when plugin is applied via settings plugin

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@runningcode runningcode force-pushed the no/settings-extension branch from 793b929 to 39ac566 Compare May 6, 2026 11:32
Comment on lines +226 to +236
org.convention(settings.org)
projectName.convention(settings.projectName)
authToken.convention(settings.authToken)
url.convention(settings.url)
debug.convention(settings.debug)
telemetry.convention(settings.telemetry)
telemetryDsn.convention(settings.telemetryDsn)
includeSourceContext.convention(settings.includeSourceContext)
autoInstallation.enabled.convention(settings.autoInstallation.enabled)
autoInstallation.sentryVersion.convention(settings.autoInstallation.sentryVersion)
}
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 applySettingsDefaults function only propagates a small subset of properties from the settings plugin, causing most configurations set in settings.gradle.kts to be silently ignored.
Severity: MEDIUM

Suggested Fix

Update the applySettingsDefaults function to propagate all relevant properties from the settings-level SentryPluginExtension to the module-level extensions. This will ensure that configurations set in settings.gradle.kts are correctly applied across all modules.

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/extensions/SentryPluginExtension.kt#L225-L236

Potential issue: When using the Sentry settings plugin, most configuration properties
set in `settings.gradle.kts` are silently ignored. The `applySettingsDefaults` function
only propagates a small subset of properties (like `org`, `project`, `authToken`) to
module-level Sentry extensions. Other properties available in the
`SentryPluginExtension` DSL, such as `uploadNativeSymbols`, `autoUploadProguardMapping`,
and `tracingInstrumentation`, have no effect when set at the settings level. This is
because a refactor reused the extension for the settings plugin but did not update the
propagation logic to handle all the newly exposed properties, creating a misleading API.

Library modules don't initialize Sentry themselves and auto-installing
dependencies could cause version conflicts with the app module.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@runningcode runningcode changed the title feat: Add settings plugin with settings-level extension [Don't review]: Add settings plugin with settings-level extension May 6, 2026
The settings plugin now only provides shared configuration. Users
apply the appropriate plugin to each module themselves.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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 d543fa2. Configure here.

includeSourceContext.convention(settings.includeSourceContext)
autoInstallation.enabled.convention(settings.autoInstallation.enabled)
autoInstallation.sentryVersion.convention(settings.autoInstallation.sentryVersion)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Settings defaults omit paired autoUploadSourceContext property

Medium Severity

applySettingsDefaults forwards includeSourceContext from settings but not its companion property autoUploadSourceContext (which includeSourceContext's own @see tag references as related). Since the settings DSL exposes autoUploadSourceContext (via the shared SentryPluginExtension class), a user could set includeSourceContext.set(true) and autoUploadSourceContext.set(false) in settings expecting source context to be generated but not uploaded. The first setting would propagate correctly, but the second would be silently ignored — every module would still auto-upload with the default true, potentially causing unintended uploads to Sentry.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d543fa2. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant