@@ -106,6 +106,20 @@ publishing {
106
106
}
107
107
}
108
108
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
+
109
123
tasks. withType(Test ). configureEach {
110
124
dependsOn publish
111
125
systemProperty " local.repo" , localRepo. toURI()
@@ -117,12 +131,17 @@ tasks.withType(Test).configureEach {
117
131
118
132
tasks. named(" test" ) {
119
133
useJUnit {
134
+ // The main test task runs everything not annotated with the MultiVersionTest category
120
135
excludeCategories ' org.gradle.android.MultiVersionTest'
121
136
}
122
137
}
123
138
139
+ // Generate a test task for each Android version and run the tests annotated with the MultiVersionTest category
124
140
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
+
126
145
javaLauncher = javaToolchains. launcherFor {
127
146
languageVersion = jdkVersionFor(androidVersion)
128
147
}
@@ -135,16 +154,8 @@ supportedVersions.keySet().each { androidVersion ->
135
154
check. dependsOn versionSpecificTest
136
155
}
137
156
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)} "
148
159
}
149
160
150
161
static def normalizeVersion (String version ) {
0 commit comments