Last active
May 29, 2022 04:44
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@arunkumar9t2 What's the advantage of this? Will the dependent tasks be skipped?