Skip to content

Instantly share code, notes, and snippets.

@technoir42
Last active September 14, 2017 20:26
Show Gist options
  • Save technoir42/e5b99c2a0cac83e3fe306488aa558b13 to your computer and use it in GitHub Desktop.
Save technoir42/e5b99c2a0cac83e3fe306488aa558b13 to your computer and use it in GitHub Desktop.
apply plugin: 'checkstyle'
checkstyle {
toolVersion = '8.2'
configFile rootProject.file('checkstyle.xml')
}
afterEvaluate { project ->
def variants
if (project.plugins.hasPlugin('com.android.application')) {
variants = android.applicationVariants
} else if (project.plugins.hasPlugin('com.android.library')) {
variants = android.libraryVariants
} else if (project.plugins.hasPlugin('com.android.feature')) {
variants = android.featureVariants
} else {
return
}
def checkstyleTask = project.tasks.create('checkstyle')
checkstyleTask.group = 'Verification'
checkstyleTask.description = 'Runs checkstyle on all variants.'
project.tasks.getByName('check').dependsOn checkstyleTask
variants.all { variant ->
def task = project.tasks.create "checkstyle${variant.name.capitalize()}", Checkstyle
task.group = 'Verification'
task.description = "Runs checkstyle on the ${variant.name} variant."
task.dependsOn variant.javaCompile
task.source variant.javaCompile.source
task.classpath = project.fileTree(variant.javaCompile.destinationDir)
task.exclude('**/BuildConfig.java', '**/R.java', '**/Manifest.java')
task.showViolations true
checkstyleTask.dependsOn task
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment