Skip to content

Instantly share code, notes, and snippets.

@arunkumar9t2
Last active May 29, 2022 04:44
Show Gist options
  • Save arunkumar9t2/6eec359cb149b23390ca02e94fcec99d to your computer and use it in GitHub Desktop.
Save arunkumar9t2/6eec359cb149b23390ca02e94fcec99d to your computer and use it in GitHub Desktop.
Gradle script that disables all test tasks if it has no test sources.
subprojects {
afterEvaluate {
def hasKotlinAndroidSourceSet = extensions.findByType(org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension)
?.sourceSets?.findByName("test")?.kotlin?.files?.size() != 0
def hasKotlinSourceSet = extensions.findByType(org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension)
?.sourceSets?.findByName("test")?.kotlin?.files?.size() != 0
if (!hasKotlinAndroidSourceSet && !hasKotlinSourceSet) {
tasks.configureEach {
if (name.contains("Test")) {
// println("${project.name}:$name")
enabled = false
}
}
}
def hasAndroidTestSourceSet = extensions.findByType(org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension)
?.sourceSets?.findByName("androidTest")?.kotlin?.files?.size() != 0
if (!hasAndroidTestSourceSet) {
tasks.configureEach {
if (name.contains("AndroidTest")) {
// println("${project.name}:$name")
enabled = false
}
}
}
}
}
@esafirm
Copy link

esafirm commented May 29, 2022

@arunkumar9t2 What's the advantage of this? Will the dependent tasks be skipped?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment