Skip to content

Commit f521ffd

Browse files
committed
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 2994300 commit f521ffd

4 files changed

Lines changed: 78 additions & 1 deletion

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.6.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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ Regardless of `useSagp`, the sample always depends on sentry-java modules from t
4040
auto-installation is disabled, so the sample never pulls a separate SDK version from Maven. Local SDK changes in your branch are picked up
4141
directly.
4242

43+
### Testing an unpublished SAGP build
44+
45+
#### I. Publish to Maven Local:
46+
47+
`-PuseSagp=true` builds check `mavenLocal()` first when resolving SAGP, so you can test a local SAGP branch by publishing it to your local
48+
Maven repository:
49+
50+
```
51+
# In your sentry-android-gradle-plugin checkout:
52+
./gradlew publishToMavenLocal
53+
```
54+
55+
Re-run `publishToMavenLocal` after each SAGP change; a previously published artifact stays in `~/.m2` and keeps winning until you republish
56+
or remove it.
57+
58+
#### II. Update `sagp` version in `libs.versions.toml` if needed
59+
60+
The sample requests the SAGP version pinned in `gradle/libs.versions.toml` (`[versions].sagp`), so either publish your branch at that
61+
version, or temporarily bump the pin to your branch's version (e.g., a `-SNAPSHOT`) without committing the change.
62+
4363
## Viewing SDK output
4464

4565
### Locally

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import com.android.build.api.artifact.SingleArtifact
22
import com.android.build.api.variant.impl.VariantImpl
33
import io.sentry.android.gradle.extensions.InstrumentationFeature
44
import io.sentry.android.gradle.extensions.SentryPluginExtension
5+
import java.io.File
6+
import java.time.Instant
57
import org.apache.tools.ant.taskdefs.condition.Os
68
import org.gradle.internal.extensions.stdlib.capitalized
79

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

2224
plugins.withId("io.sentry.android.gradle") {
25+
logSagpOrigin()
26+
2327
// Extension configs match non-SAGP builds. Update locally to test your feature.
2428
extensions.configure<SentryPluginExtension>("sentry") {
2529
autoInstallation.enabled.set(false)
@@ -230,3 +234,46 @@ abstract class ToggleNativeLoggingTask : Exec() {
230234
)
231235
}
232236
}
237+
238+
fun Project.logSagpOrigin() {
239+
// A locally published SAGP in ~/.m2 silently shadows the released artifact (see README,
240+
// "Testing an unpublished SAGP build"); we log so developers don't wonder what's going on.
241+
val sagpVersion =
242+
SentryPluginExtension::class
243+
.java
244+
.protectionDomain
245+
.codeSource
246+
?.location
247+
?.toURI()
248+
?.let { File(it).name }
249+
?.removePrefix("sentry-android-gradle-plugin-")
250+
?.removeSuffix(".jar")
251+
252+
val sagpLocalJar =
253+
sagpVersion?.let {
254+
File(
255+
System.getProperty("user.home"),
256+
".m2/repository/io/sentry/sentry-android-gradle-plugin/$it/sentry-android-gradle-plugin-$it.jar",
257+
)
258+
}
259+
260+
val sagpOrigin =
261+
when {
262+
sagpVersion == null -> "unknown origin"
263+
sagpLocalJar?.isFile == true ->
264+
"mavenLocal (published ${Instant.ofEpochMilli(sagpLocalJar.lastModified())})"
265+
else -> "remote repository"
266+
}
267+
268+
val colorize =
269+
gradle.startParameter.consoleOutput != org.gradle.api.logging.configuration.ConsoleOutput.Plain
270+
val (magenta, reset) = if (colorize) "\u001B[35m" to "\u001B[0m" else "" to ""
271+
272+
logger.lifecycle(
273+
"\n{}🧩 Applied Sentry Android Gradle Plugin {} from {}{}",
274+
magenta,
275+
sagpVersion ?: "<unknown version>",
276+
sagpOrigin,
277+
reset,
278+
)
279+
}

settings.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
22

33
pluginManagement {
44
repositories {
5+
// Prefer local SAGP artifact if one exists; otherwise fall back to libs.versions.toml.
6+
if (providers.gradleProperty("useSagp").orNull.equals("true", ignoreCase = true)) {
7+
mavenLocal {
8+
content {
9+
includeGroup("io.sentry")
10+
includeGroup("io.sentry.android.gradle")
11+
}
12+
}
13+
}
514
mavenCentral()
615
gradlePluginPortal()
716
}

0 commit comments

Comments
 (0)