Skip to content

Commit d7afb6d

Browse files
authored
test(gradle): Add isolated-projects compatibility test (EME-1072) (#1160)
* test(gradle): Add isolated-projects compatibility test (EME-1072) Adds an integration test that applies the plugin to a consumer project with org.gradle.unsafe.isolated-projects=true enabled and asserts that the build succeeds without isolation violations. The fixture bypasses the shared root build.gradle written by BaseSentryPluginTest because it relies on allprojects {} and subprojects {}, both of which are incompatible with Isolated Projects. Instead, this test wires repositories, Android config, and plugin application per-project. * test(gradle): Exercise multi-module + more plugin features Replaces the single-module fixture with an :app + :library setup where :app depends on :library. This is where Isolated Projects compatibility actually matters — single-module builds don't exercise cross-project configuration at all. Enables autoUploadProguardMapping and telemetry to broaden coverage of plugin code paths under Isolated Projects. autoInstallation stays disabled because it accesses Project.group on sibling projects during dependency graph traversal at configuration time; tracked in EME-1072. * test(gradle): Fix inert violation substring in isolated-projects assert The old check for "problems were found reporting" never matches Gradle output — the actual phrases are "problems were found storing the configuration cache" or "problems were found reusing the configuration cache". Broadening to "problems were found " catches both, so the defensive check actually has teeth now.
1 parent 7938856 commit d7afb6d

1 file changed

Lines changed: 167 additions & 0 deletions

File tree

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
package io.sentry.android.gradle.integration
2+
3+
import io.sentry.BuildConfig
4+
import io.sentry.android.gradle.util.AgpVersions
5+
import io.sentry.android.gradle.util.GradleVersions
6+
import io.sentry.android.gradle.util.SemVer
7+
import java.io.File
8+
import kotlin.test.assertFalse
9+
import kotlin.test.assertTrue
10+
import org.gradle.testkit.runner.internal.PluginUnderTestMetadataReading
11+
import org.gradle.util.GradleVersion
12+
import org.hamcrest.CoreMatchers.`is`
13+
import org.junit.Assume.assumeThat
14+
import org.junit.Test
15+
16+
class SentryPluginIsolatedProjectsTest :
17+
BaseSentryPluginTest(BuildConfig.AgpVersion, GradleVersion.current().version) {
18+
19+
@Test
20+
fun `plugin is compatible with isolated projects in a multi-module build`() {
21+
assumeThat(
22+
"Isolated Projects requires AGP 8.3.0+ and Gradle 8.0+",
23+
SemVer.parse(BuildConfig.AgpVersion) >= AgpVersions.VERSION_8_3_0 &&
24+
GradleVersions.CURRENT >= GradleVersions.VERSION_8_0,
25+
`is`(true),
26+
)
27+
28+
writeIsolatedProjectsFixture()
29+
30+
runner.appendArguments(":app:assembleDebug").appendArguments("--configuration-cache")
31+
32+
val output = runner.build().output
33+
34+
assertTrue(output) { "BUILD SUCCESSFUL" in output }
35+
// Sanity-check that isolated-projects was actually active during this build —
36+
// otherwise the test would silently degrade into a plain config-cache test.
37+
assertTrue(output) { "isolated projects" in output.lowercase() }
38+
assertFalse(
39+
"problems were found " in output || "cannot access '" in output,
40+
"Expected no isolated-projects violations, but got:\n$output",
41+
)
42+
}
43+
44+
private fun writeIsolatedProjectsFixture() {
45+
// Replace the fixture written by BaseSentryPluginTest — its root build.gradle
46+
// uses allprojects {} and subprojects {}, which are fundamentally incompatible
47+
// with Gradle's isolated-projects feature. Instead, wire everything per-project
48+
// and add an Android library module that :app depends on, so we exercise
49+
// cross-project configuration (the interesting scenario for Isolated Projects).
50+
//
51+
// autoInstallation is intentionally left disabled: it walks the dependency
52+
// graph at configuration time and reaches into sibling projects' metadata
53+
// (Project.group), which violates Isolated Projects. Tracked in EME-1072.
54+
val pluginClasspath =
55+
PluginUnderTestMetadataReading.readImplementationClasspath()
56+
.joinToString(separator = ", ") { "\"$it\"" }
57+
.replace(File.separator, "/")
58+
59+
File(testProjectDir.root, "settings.gradle")
60+
.writeText(
61+
// language=Groovy
62+
"""
63+
include ':app', ':library'
64+
"""
65+
.trimIndent()
66+
)
67+
68+
File(testProjectDir.root, "gradle.properties")
69+
.writeText(
70+
"""
71+
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8
72+
org.gradle.daemon=false
73+
org.gradle.unsafe.isolated-projects=true
74+
android.useAndroidX=true
75+
android.overrideVersionCheck=true
76+
"""
77+
.trimIndent()
78+
)
79+
80+
File(testProjectDir.root, "build.gradle")
81+
.writeText(
82+
// language=Groovy
83+
"""
84+
buildscript {
85+
repositories {
86+
google()
87+
gradlePluginPortal()
88+
mavenCentral()
89+
}
90+
dependencies {
91+
classpath 'com.android.tools.build:gradle:$androidGradlePluginVersion'
92+
classpath files($pluginClasspath)
93+
}
94+
}
95+
"""
96+
.trimIndent()
97+
)
98+
99+
File(testProjectDir.root, "app/build.gradle")
100+
.writeText(
101+
// language=Groovy
102+
"""
103+
plugins {
104+
id 'com.android.application'
105+
id 'io.sentry.android.gradle'
106+
}
107+
108+
repositories {
109+
google()
110+
mavenCentral()
111+
}
112+
113+
android {
114+
namespace 'com.example'
115+
compileSdkVersion 35
116+
defaultConfig {
117+
applicationId 'com.example'
118+
minSdkVersion 21
119+
}
120+
}
121+
122+
dependencies {
123+
implementation project(':library')
124+
}
125+
126+
sentry {
127+
autoUploadProguardMapping = true
128+
autoInstallation.enabled = false
129+
telemetry = true
130+
}
131+
"""
132+
.trimIndent()
133+
)
134+
135+
val libraryDir = File(testProjectDir.root, "library").apply { mkdirs() }
136+
File(libraryDir, "build.gradle")
137+
.writeText(
138+
// language=Groovy
139+
"""
140+
plugins {
141+
id 'com.android.library'
142+
id 'io.sentry.android.gradle'
143+
}
144+
145+
repositories {
146+
google()
147+
mavenCentral()
148+
}
149+
150+
android {
151+
namespace 'com.example.library'
152+
compileSdkVersion 35
153+
defaultConfig {
154+
minSdkVersion 21
155+
}
156+
}
157+
158+
sentry {
159+
autoUploadProguardMapping = false
160+
autoInstallation.enabled = false
161+
telemetry = false
162+
}
163+
"""
164+
.trimIndent()
165+
)
166+
}
167+
}

0 commit comments

Comments
 (0)