igor.wojda
10/04/2018, 1:20 PMdetect
, ktlint
, android lint
. These translates to below grade tasks:
./gradlew detektCheck
./gradlew ktlintCheck
./gradlew lint (this task does not exist gradle will select task from app module :app:lint)
As far I I know grade task can’t run another grade task and it can jus depend on another task (with makes perfect sense). Now I was able to write simple task (Kotlin Grade script) that runs detekt
and ktlint
checks (by using dependency mechanizm)
task("staticCheck") {
dependsOn("detekt", "ktlintCheck")
}
Now I am struggling with adding the (Android) lint
. I can’t simply add lint
to dependencies (dependsOn("detekt", "ktlintCheck", "lint")
) because lint
task does not exists in configuration phase:
task("staticCheck") {
val lintDependencies = subprojects.mapNotNull { it.tasks.findByName("lint") } //empty list
doLast {
val lintDependencies = subprojects.mapNotNull { it.tasks.findByName("lint") } //list containing few modules, however I can't use dependsOn here
}
}
What is the best way of running all static analysis checks in single task?Czar
10/04/2018, 7:39 PMigor.wojda
10/06/2018, 3:24 PMtask("staticCheck") {
afterEvaluate {
val lintDependencies = subprojects.mapNotNull { "${it.name}:lint" }
dependsOn(lintDependencies + listOf("ktlintCheck", "detekt"))
}
}
The only issue now is that I am assuming that lint
task is available in all modules (witch is not true for pure java modules) . I tried to retrieve list of lint tasks or plugin for module (subprojects.filter { it.plugins.hasPlugin(GradlePluginId.androidApplication) }
) but in botch cases these variables are empty - like module would not be evaluated