0

Following https://stackoverflow.com/a/48494454/3286489, I could now run the linting tasks (both in CLI and run in Android Studio) before compile my app.

My code as below.

android {
//....
    lintOptions {
        abortOnError true
    }
}

tasks.whenTaskAdded { task ->
    if (task.name == 'compileDebugSources' || task.name == 'compileReleaseSources') {
        task.dependsOn lint
        task.mustRunAfter lint
    }
}

However I dislike

task.name == 'compileDebugSources' || task.name == 'compileReleaseSources'

Is there a way to combine them and still get it working?

Elye
  • 53,639
  • 54
  • 212
  • 474
  • I could also use `task.name.startsWith('compile') && task.name.endsWith('Sources')` but still not nice. – Elye Sep 01 '18 at 22:54

1 Answers1

0

You could use a regex :

tasks.whenTaskAdded { task ->
    if (task.name.matches('compile(.*)Sources')) {
        task.dependsOn lint
        task.mustRunAfter lint
    }
}
M.Ricciuti
  • 11,070
  • 2
  • 34
  • 54