Skip to content

Commit e4dcfc9

Browse files
committed
Force correct JUnit BOM for our own internal instrumentation tests
1 parent 2dcf305 commit e4dcfc9

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

instrumentation/buildSrc/src/main/java/LocalProjectDependencyConfigurator.kt

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
1+
import extensions.library
2+
import extensions.libs
13
import org.gradle.api.Project
24

3-
// Use local project dependencies on android-test instrumentation libraries
4-
// for the modules inside this repository, instead of relying on their Maven coordinates.
5-
// This is not needed for normal consumers, but we want it to test our own code.
65
private val instrumentationLibraryRegex =
76
Regex("de\\.mannodermaus\\.junit5:android-test-([a-z0-9]+)(-.+)?:")
87

98
fun Project.replaceAndroidTestLibsWithLocalProjectDependencies() {
109
val self = this
1110

1211
configurations.all {
13-
if ("DebugAndroidTestRuntimeClasspath" in name) {
14-
resolutionStrategy.dependencySubstitution.all {
12+
if ("DebugAndroidTestRuntimeClasspath" !in name) {
13+
return@all
14+
}
15+
16+
resolutionStrategy {
17+
// Force a specific version of the JUnit BOM, depending on the actual configuration
18+
SupportedJUnit.values().forEach { junit ->
19+
if (name.startsWith(junit.variant)) {
20+
force(
21+
when (junit) {
22+
SupportedJUnit.JUnit5 -> libs.library("junit-framework-bom5")
23+
SupportedJUnit.JUnit6 -> libs.library("junit-framework-bom6")
24+
}
25+
)
26+
}
27+
}
28+
29+
// Use local project dependencies on android-test instrumentation libraries
30+
// for the modules inside this repository, instead of relying on their Maven coords.
31+
// This is not needed for normal consumers, but we need it to test our own code.
32+
dependencySubstitution.all {
1533
instrumentationLibraryRegex.find(requested.toString())?.let { result ->
1634
val replacement = project(":${result.groupValues[1]}")
1735
println(
1836
"In $self, replace androidTest dependency '$requested' with $replacement"
1937
)
20-
useTarget(replacement)
38+
useTarget(replacement, "Use $replacement to substitute dependency '$requested'")
2139
}
2240
}
2341
}

instrumentation/compose/build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ dependencies {
4545
androidTestImplementation(libs.junit.jupiter.api)
4646
androidTestImplementation(libs.junit.jupiter.params)
4747
androidTestImplementation(libs.espresso)
48-
49-
androidTestRuntimeOnly(project(":runner"))
50-
androidTestRuntimeOnly(libs.androidx.test.runner)
5148
}
5249

5350
project.configureDeployment(Artifacts.Instrumentation.Compose)

instrumentation/core/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ dependencies {
4141
androidTestImplementation(libs.junit.jupiter.api)
4242
androidTestImplementation(libs.junit.jupiter.params)
4343
androidTestImplementation(libs.espresso)
44-
androidTestRuntimeOnly(project(":runner"))
4544

4645
testImplementation(project(":testutil"))
4746
}

instrumentation/sample/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,4 @@ dependencies {
5555
androidTestImplementation(libs.junit.jupiter.api)
5656
androidTestImplementation(libs.junit.jupiter.params)
5757
androidTestImplementation(libs.espresso)
58-
androidTestImplementation(project(":core"))
59-
androidTestRuntimeOnly(project(":runner"))
6058
}

0 commit comments

Comments
 (0)