Skip to content

Commit d92c9d7

Browse files
committed
Clean up multi-version build logic
1 parent 840a4aa commit d92c9d7

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

build.gradle

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ publishing {
106106
}
107107
}
108108

109+
// This is used by github actions to split out jobs by Android version test task
110+
def generatedBuildResources = "$buildDir/build-resources"
111+
tasks.register('generateTestTasksJson') {
112+
def outputFile = file("${generatedBuildResources}/androidTestTasks.json")
113+
inputs.property "supportedVersions", supportedVersions
114+
outputs.dir generatedBuildResources
115+
doLast {
116+
outputFile.text = new JsonBuilder(
117+
['test'] + (supportedVersions.keySet().collect {androidVersion -> androidTestTaskName(androidVersion) })
118+
).toString()
119+
}
120+
}
121+
122+
109123
tasks.withType(Test).configureEach {
110124
dependsOn publish
111125
systemProperty "local.repo", localRepo.toURI()
@@ -117,12 +131,17 @@ tasks.withType(Test).configureEach {
117131

118132
tasks.named("test") {
119133
useJUnit {
134+
// The main test task runs everything not annotated with the MultiVersionTest category
120135
excludeCategories 'org.gradle.android.MultiVersionTest'
121136
}
122137
}
123138

139+
// Generate a test task for each Android version and run the tests annotated with the MultiVersionTest category
124140
supportedVersions.keySet().each { androidVersion ->
125-
def versionSpecificTest = tasks.register("testAndroid${normalizeVersion(androidVersion)}", Test) {
141+
def versionSpecificTest = tasks.register(androidTestTaskName(androidVersion), Test) {
142+
description = "Runs the multi-version tests for AGP ${androidVersion}"
143+
group = "verification"
144+
126145
javaLauncher = javaToolchains.launcherFor {
127146
languageVersion = jdkVersionFor(androidVersion)
128147
}
@@ -135,16 +154,8 @@ supportedVersions.keySet().each { androidVersion ->
135154
check.dependsOn versionSpecificTest
136155
}
137156

138-
def generatedBuildResources = "$buildDir/build-resources"
139-
tasks.register('generateTestTasksJson') {
140-
def outputFile = file("${generatedBuildResources}/androidTestTasks.json")
141-
inputs.property "supportedVersions", supportedVersions
142-
outputs.dir generatedBuildResources
143-
doLast {
144-
outputFile.text = new JsonBuilder(
145-
['test'] + (supportedVersions.keySet().collect { "testAndroid${normalizeVersion(it)}"})
146-
).toString()
147-
}
157+
static def androidTestTaskName(String androidVersion) {
158+
return "testAndroid${normalizeVersion(androidVersion)}"
148159
}
149160

150161
static def normalizeVersion(String version) {

0 commit comments

Comments
 (0)