Skip to content

Commit 39bbcf1

Browse files
romtsnclaude
andcommitted
build: Align SDK modules to one version through sentry-bom
Gradle resolves version conflicts per module, so a build could mix SDK modules of different versions, for example a newer sentry-android-core with an older sentry-android-fragment that the Gradle plugin or another library pulled in. That fails at runtime with NoSuchMethodError or the mixed versions check. Every published module now depends on sentry-bom as a platform. Gradle then moves all SDK modules of a consumer to the highest version present. Maven does not apply the dependencyManagement of a dependency's POM, so Maven builds resolve as before. The BOM and the root build share one isBomMember() check, so the modules that depend on the BOM are exactly the ones it constrains. Refs #5105 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b05d954 commit 39bbcf1

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

‎build.gradle.kts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ subprojects {
126126
assignAarTypes()
127127
}
128128

129+
// with the BOM as a platform, Gradle aligns all SDK modules of a consumer to one version
130+
val configuration =
131+
if (plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) "commonMainApi" else "api"
132+
// parent projects such as sentry-opentelemetry have no api configuration and publish nothing
133+
if (Config.BuildScript.isBomMember(this@subprojects.name) && configuration in configurations.names) {
134+
dependencies.add(configuration, dependencies.platform(project(":sentry-bom")))
135+
}
136+
129137
// this is needed for sentry-unity to consume our artifacts locally as proper maven publication
130138
configure<PublishingExtension> {
131139
repositories {

‎buildSrc/src/main/java/Config.kt‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,12 @@ object Config {
109109
val androidXLibs = listOf(
110110
"androidx.core:core"
111111
)
112+
113+
// published modules that sentry-bom constrains, and that depend on it to stay aligned
114+
fun isBomMember(projectName: String): Boolean =
115+
!projectName.startsWith("sentry-samples") &&
116+
!projectName.endsWith("-bom") &&
117+
!projectName.contains("test", ignoreCase = true) &&
118+
!projectName.contains("sentry-android-distribution")
112119
}
113120
}

‎sentry-bom/build.gradle.kts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ plugins {
66
dependencies {
77
constraints {
88
project.rootProject.subprojects
9-
.filter {
10-
!it.name.startsWith("sentry-samples") &&
11-
it.name != project.name &&
12-
!it.name.endsWith("-bom") &&
13-
!it.name.contains("test", ignoreCase = true) &&
14-
!it.name.contains("sentry-android-distribution")
15-
}
9+
.filter { Config.BuildScript.isBomMember(it.name) }
1610
.forEach { project ->
1711
evaluationDependsOn(project.path)
1812
project.publishing.publications

0 commit comments

Comments
 (0)