Skip to content

Commit

Permalink
Clean up multi-version build logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ghale committed Feb 24, 2021
1 parent 840a4aa commit d92c9d7
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ publishing {
}
}

// This is used by github actions to split out jobs by Android version test task
def generatedBuildResources = "$buildDir/build-resources"
tasks.register('generateTestTasksJson') {
def outputFile = file("${generatedBuildResources}/androidTestTasks.json")
inputs.property "supportedVersions", supportedVersions
outputs.dir generatedBuildResources
doLast {
outputFile.text = new JsonBuilder(
['test'] + (supportedVersions.keySet().collect {androidVersion -> androidTestTaskName(androidVersion) })
).toString()
}
}


tasks.withType(Test).configureEach {
dependsOn publish
systemProperty "local.repo", localRepo.toURI()
Expand All @@ -117,12 +131,17 @@ tasks.withType(Test).configureEach {

tasks.named("test") {
useJUnit {
// The main test task runs everything not annotated with the MultiVersionTest category
excludeCategories 'org.gradle.android.MultiVersionTest'
}
}

// Generate a test task for each Android version and run the tests annotated with the MultiVersionTest category
supportedVersions.keySet().each { androidVersion ->
def versionSpecificTest = tasks.register("testAndroid${normalizeVersion(androidVersion)}", Test) {
def versionSpecificTest = tasks.register(androidTestTaskName(androidVersion), Test) {
description = "Runs the multi-version tests for AGP ${androidVersion}"
group = "verification"

javaLauncher = javaToolchains.launcherFor {
languageVersion = jdkVersionFor(androidVersion)
}
Expand All @@ -135,16 +154,8 @@ supportedVersions.keySet().each { androidVersion ->
check.dependsOn versionSpecificTest
}

def generatedBuildResources = "$buildDir/build-resources"
tasks.register('generateTestTasksJson') {
def outputFile = file("${generatedBuildResources}/androidTestTasks.json")
inputs.property "supportedVersions", supportedVersions
outputs.dir generatedBuildResources
doLast {
outputFile.text = new JsonBuilder(
['test'] + (supportedVersions.keySet().collect { "testAndroid${normalizeVersion(it)}"})
).toString()
}
static def androidTestTaskName(String androidVersion) {
return "testAndroid${normalizeVersion(androidVersion)}"
}

static def normalizeVersion(String version) {
Expand Down

0 comments on commit d92c9d7

Please sign in to comment.