checkstyle.gradle 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. apply plugin: 'checkstyle'
  2. dependencies {
  3. checkstyle 'com.puppycrawl.tools:checkstyle:8.20'
  4. }
  5. def checkstyleConfigDir = file("${buildscript.sourceFile.parentFile}/enforcement/checkstyle")
  6. checkstyle {
  7. configDir = checkstyleConfigDir
  8. configProperties.checkstyleConfigDir = checkstyleConfigDir
  9. maxWarnings = 500
  10. }
  11. plugins.withType(GroovyBasePlugin) {
  12. sourceSets.all { sourceSet ->
  13. tasks.register("${sourceSet.getTaskName('checkstyle', 'groovy')}", Checkstyle) {
  14. configFile = new File(checkstyleConfigDir, "checkstyle-groovy.xml")
  15. source(allGroovy)
  16. classpath = sourceSet.compileClasspath
  17. reports.xml.destination = new File(reportsDir, "${sourceSet.name}-groovy.xml")
  18. }
  19. }
  20. }
  21. def checkstyleTasks = tasks.withType(Checkstyle)
  22. tasks.register("checkstyle") {
  23. dependsOn checkstyleTasks
  24. }
  25. check.dependsOn checkstyleTasks
  26. tasks.withType(Test).configureEach {
  27. mustRunAfter checkstyleTasks
  28. }
  29. // Verification seems broken on Java 9.
  30. apply plugin: 'com.github.sherter.google-java-format'
  31. googleJavaFormat {
  32. source = sourceSets*.allJava
  33. exclude '**/build/**/*.java'
  34. }
  35. tasks.withType(Checkstyle).configureEach {
  36. mustRunAfter verifyGoogleJavaFormat
  37. }