I would like to be able to run the lint task when I\'m building projects with the android studio to ensure the lint rules are being followed.
I have tried using task
To do this in build.gradle, add the following lines to your build.gradle:
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
def lintTask = tasks["lint${variant.name.capitalize()}"]
output.assemble.dependsOn lintTask
}
}
...
}
This makes all of your assemble tasks depend on the lint task effectively running them before every assemble call that is executed by Android Studio.
Edit
With Android Gradle Plugin 3.3 and Gradle 5.x this is a revised version using Kotlin script:
applicationVariants.all {
val lintTask = tasks["lint${name.capitalize()}"]
assembleProvider.get().dependsOn.add(lintTask)
}