Skip to content

Commit 9d2f4e3

Browse files
authored
chore(samples-android): Support mavenLocal for builds that apply the SAGP (#5539)
chore(samples-android): Support mavenLocal for builds that apply the SAGP Adds wiring that lets us prefer mavenLocal SAGP artifacts, when present, for Android sample app builds that set -PuseSagp=true. If no local artifact is found, we fall back to libs.versions.toml.
1 parent aab75f7 commit 9d2f4e3

4 files changed

Lines changed: 39 additions & 17 deletions

File tree

gradle/libs.versions.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ otelInstrumentationAlpha = "2.26.0-alpha"
2929
otelSemanticConventions = "1.40.0"
3030
otelSemanticConventionsAlpha = "1.40.0-alpha"
3131
retrofit = "2.9.0"
32+
sagp = "6.10.0"
3233
slf4j = "1.7.30"
3334
springboot2 = "2.7.18"
3435
springboot3 = "3.5.0"
@@ -66,7 +67,7 @@ springboot4 = { id = "org.springframework.boot", version.ref = "springboot4" }
6667
spring-dependency-management = { id = "io.spring.dependency-management", version = "1.1.7" }
6768
gretty = { id = "org.gretty", version = "4.0.0" }
6869
animalsniffer = { id = "ru.vyarus.animalsniffer", version = "2.0.1" }
69-
sentry = { id = "io.sentry.android.gradle", version = "6.6.0"}
70+
sentry = { id = "io.sentry.android.gradle", version.ref = "sagp"}
7071
shadow = { id = "com.gradleup.shadow", version = "9.4.1" }
7172

7273
[libraries]

sentry-samples/sentry-samples-android/README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,44 @@ or simply open the project in Android Studio and run the `sentry-samples-android
1616
You can also apply the [Sentry Android Gradle Plugin](https://github.com/getsentry/sentry-android-gradle-plugin) (SAGP) when building (not applied by default):
1717

1818
```
19-
./gradlew :sentry-samples:sentry-samples-android:installDebug -PuseSagp=true
19+
./gradlew :sentry-samples:sentry-samples-android:installDebug -PuseSagp
2020
```
2121

22-
In Android Studio, add `useSagp=true` to `gradle.properties` or pass it as a Gradle project property.
22+
In Android Studio, add `useSagp=` (empty value) to `gradle.properties`, or pass `-PuseSagp` as a Gradle project property.
2323

2424
## Build modes
2525

2626
### With or without SAGP
2727

2828
The sample app can be built with or without the SAGP.
2929

30-
| Gradle Property | Required | Purpose |
31-
|-----------------|--------------------------|----------------------------------------------------------------------------------------------------------------|
32-
| `useSagp` | No (defaults to `false`) | When `true`, apply SAGP when building the sample app. When false or absent, build the sample app without SAGP. |
30+
| Gradle Property | Required | Purpose |
31+
|-----------------|----------|-------------------------------------------------------------------------------------------------|
32+
| `useSagp` | No | When present, apply SAGP when building the sample app. Omit the property to build without SAGP. |
3333

3434
You can configure SAGP properties via the lambda passed to `extensions.configure<SentryPluginExtension>("sentry")` in the sample app's
3535
`build.gradle.kts` file.
3636

37-
### Builds against your local sentry-java branch
37+
### Testing an unpublished SAGP build
3838

39-
Regardless of `useSagp`, the sample always depends on sentry-java modules from this monorepo (e.g., `projects.sentryAndroid`). SAGP's SDK
40-
auto-installation is disabled, so the sample never pulls a separate SDK version from Maven. Local SDK changes in your branch are picked up
41-
directly.
39+
`-PuseSagp` builds check `mavenLocal()` first when resolving SAGP. To test a local SAGP branch:
40+
41+
1. In your `sentry-android-gradle-plugin` checkout, temporarily set a unique local version in `plugin-build/gradle.properties` (e.g.
42+
`6.10.0-LOCAL`) and publish to Maven Local:
43+
44+
```
45+
./gradlew -p plugin-build publishToMavenLocal
46+
```
47+
48+
Re-run `publishToMavenLocal` after each SAGP change.
49+
50+
2. Temporarily bump the `sagp` pin in `gradle/libs.versions.toml` to match that version.
51+
52+
Then build from sentry-java:
53+
54+
```
55+
./gradlew :sentry-samples:sentry-samples-android:installDebug -PuseSagp
56+
```
4257

4358
## Viewing SDK output
4459

sentry-samples/sentry-samples-android/build.gradle.kts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ plugins {
1212
alias(libs.plugins.sentry) apply false
1313
}
1414

15-
val useSagp =
16-
providers.gradleProperty("useSagp").map { it.equals("true", ignoreCase = true) }.orElse(false)
17-
18-
if (useSagp.get()) {
15+
if (providers.gradleProperty("useSagp").isPresent) {
1916
apply(plugin = "io.sentry.android.gradle")
2017
}
2118

settings.gradle.kts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
22

33
pluginManagement {
4-
repositories {
5-
mavenCentral()
6-
gradlePluginPortal()
4+
repositories {
5+
// Prefer local SAGP artifact if one exists; otherwise fall back to libs.versions.toml.
6+
if (providers.gradleProperty("useSagp").isPresent) {
7+
mavenLocal {
8+
content {
9+
includeGroup("io.sentry")
10+
includeGroup("io.sentry.android.gradle")
11+
}
12+
}
713
}
14+
mavenCentral()
15+
gradlePluginPortal()
16+
}
817
}
918

1019
plugins {

0 commit comments

Comments
 (0)