I want to create a custom gradle task for an Android project, that will call chain of other tasks depends on build flavor and build configuration.
So, that what I do in my build.gradle.kts (we use kotlin script)
gradle.projectsEvaluated {
rootProject.allprojects.filter { project ->
!Config.CodeQuality.ignoredProjects.contains(project.name)
}.forEach { project ->
project.tasks.filter { task ->
task.name.startsWith("lint")
}.forEach { task ->
val taskSyfix = task.name.drop(4)
val taskName = "codeQuality$taskSyfix"
println("qualityscripts create task $taskName")
project.tasks.create(taskName) {
group = "verification"
dependsOn("checkstyle", "deteltCkeck", "ktlint", task.name)
}
}
}
}
So than if I run ./gradlew tasks
...
Verification tasks
------------------
check - Runs all checks. checkstyle - Runs checkstyle.
codeQuality
codeQualityDebug
codeQualityDevMenuFlavor1Debug
codeQualityDevMenuFlavor1Release
codeQualityDevMenuFlavor2Debug
codeQualityDevMenuFlavor2Release
...
So they exist. But then, if I try to run any, I got next error:
- What went wrong: Task 'codeQualityDevMenuFlavor1Debug' not found in root project 'myproject-android'.