Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ otelInstrumentationAlpha = "2.26.0-alpha"
otelSemanticConventions = "1.40.0"
otelSemanticConventionsAlpha = "1.40.0-alpha"
retrofit = "2.9.0"
sagp = "6.6.0"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we use 6.10.0?

slf4j = "1.7.30"
springboot2 = "2.7.18"
springboot3 = "3.5.0"
Expand Down Expand Up @@ -66,7 +67,7 @@ springboot4 = { id = "org.springframework.boot", version.ref = "springboot4" }
spring-dependency-management = { id = "io.spring.dependency-management", version = "1.1.7" }
gretty = { id = "org.gretty", version = "4.0.0" }
animalsniffer = { id = "ru.vyarus.animalsniffer", version = "2.0.1" }
sentry = { id = "io.sentry.android.gradle", version = "6.6.0"}
sentry = { id = "io.sentry.android.gradle", version.ref = "sagp"}
shadow = { id = "com.gradleup.shadow", version = "9.4.1" }

[libraries]
Expand Down
20 changes: 20 additions & 0 deletions sentry-samples/sentry-samples-android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ Regardless of `useSagp`, the sample always depends on sentry-java modules from t
auto-installation is disabled, so the sample never pulls a separate SDK version from Maven. Local SDK changes in your branch are picked up
directly.

### Testing an unpublished SAGP build

#### I. Publish to Maven Local:

`-PuseSagp=true` builds check `mavenLocal()` first when resolving SAGP, so you can test a local SAGP branch by publishing it to your local
Maven repository:

```
# In your sentry-android-gradle-plugin checkout:
./gradlew publishToMavenLocal
```

Re-run `publishToMavenLocal` after each SAGP change; a previously published artifact stays in `~/.m2` and keeps winning until you republish
or remove it.

#### II. Update `sagp` version in `libs.versions.toml` if needed

The sample requests the SAGP version pinned in `gradle/libs.versions.toml` (`[versions].sagp`), so either publish your branch at that
version, or temporarily bump the pin to your branch's version (e.g., a `-SNAPSHOT`) without committing the change.

## Viewing SDK output

### Locally
Expand Down
47 changes: 47 additions & 0 deletions sentry-samples/sentry-samples-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import com.android.build.api.artifact.SingleArtifact
import com.android.build.api.variant.impl.VariantImpl
import io.sentry.android.gradle.extensions.InstrumentationFeature
import io.sentry.android.gradle.extensions.SentryPluginExtension
import java.io.File
import java.time.Instant
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.internal.extensions.stdlib.capitalized

Expand All @@ -20,6 +22,8 @@ if (useSagp.get()) {
}

plugins.withId("io.sentry.android.gradle") {
logSagpOrigin()

// Extension configs match non-SAGP builds. Update locally to test your feature.
extensions.configure<SentryPluginExtension>("sentry") {
autoInstallation.enabled.set(false)
Expand Down Expand Up @@ -230,3 +234,46 @@ abstract class ToggleNativeLoggingTask : Exec() {
)
}
}

fun Project.logSagpOrigin() {
// A locally published SAGP in ~/.m2 silently shadows the released artifact (see README,
// "Testing an unpublished SAGP build"); we log so developers don't wonder what's going on.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems prone to breaking. I would just make sure to use a unique version for publishing and then you are sure that you are using it.
If you are still unsure you can check a build scan to verify where it came from.

val sagpVersion =
SentryPluginExtension::class
.java
.protectionDomain
.codeSource
?.location
?.toURI()
?.let { File(it).name }
?.removePrefix("sentry-android-gradle-plugin-")
?.removeSuffix(".jar")

val sagpLocalJar =
sagpVersion?.let {
File(
System.getProperty("user.home"),
".m2/repository/io/sentry/sentry-android-gradle-plugin/$it/sentry-android-gradle-plugin-$it.jar",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you know if we can rely on the artifact always being here? This seems prone to breaking.

Is this configuration cache compatible?

)
}

val sagpOrigin =
when {
sagpVersion == null -> "unknown origin"
sagpLocalJar?.isFile == true ->
"mavenLocal (published ${Instant.ofEpochMilli(sagpLocalJar.lastModified())})"
else -> "remote repository"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SAGP origin log misleading

Low Severity

logSagpOrigin labels the plugin as mavenLocal whenever a matching JAR exists under ~/.m2, even when Gradle actually loaded SAGP from a remote cache, so the lifecycle message can misstate which artifact was applied.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f521ffd. Configure here.

}

val colorize =
gradle.startParameter.consoleOutput != org.gradle.api.logging.configuration.ConsoleOutput.Plain
val (magenta, reset) = if (colorize) "\u001B[35m" to "\u001B[0m" else "" to ""

logger.lifecycle(
"\n{}🧩 Applied Sentry Android Gradle Plugin {} from {}{}",
magenta,
sagpVersion ?: "<unknown version>",
sagpOrigin,
reset,
)
}
9 changes: 9 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

pluginManagement {
repositories {
// Prefer local SAGP artifact if one exists; otherwise fall back to libs.versions.toml.
if (providers.gradleProperty("useSagp").orNull.equals("true", ignoreCase = true)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing useSagp property NPE

High Severity

When useSagp is absent, providers.gradleProperty("useSagp").orNull is null and calling .equals("true", …) on that receiver throws a null-pointer exception during settings evaluation, so default builds without the property can fail before configuration.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f521ffd. Configure here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is true.

mavenLocal {
content {
includeGroup("io.sentry")
includeGroup("io.sentry.android.gradle")
}
}
}
mavenCentral()
gradlePluginPortal()
}
Expand Down
Loading