From 44e822ed86049ab30b20c9c6e47571eb76b80d51 Mon Sep 17 00:00:00 2001 From: gbrodman Date: Mon, 28 Jan 2019 13:57:32 -0800 Subject: [PATCH] Add Checkstyle and Error Prone to the Gradle build We make some modifications to the internal Google checkstyle file because Google's linter uses a modified build of Checkstyle that introduces some new classes and allows for more specific checks than the open-source Checkstyle (e.g. only enforcing UPPER_SNAKE_CASE on deeply immutable fields). There exists a public Checkstyle file that purports to be the Google java format file (https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml) but it doesn't quite match up with what the internal linter says in certain situations (e.g. what operators must/can appear on new lines). The suppressions are basically "don't run on generated code + don't care about Javadoc in test code" ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=231283700 --- gradle/build.gradle | 24 +++ gradle/config/checkstyle/checkstyle.xml | 251 ++++++++++++++++++++++ gradle/config/checkstyle/suppressions.xml | 12 ++ 3 files changed, 287 insertions(+) create mode 100644 gradle/config/checkstyle/checkstyle.xml create mode 100644 gradle/config/checkstyle/suppressions.xml diff --git a/gradle/build.gradle b/gradle/build.gradle index 874108451..f76ba710c 100644 --- a/gradle/build.gradle +++ b/gradle/build.gradle @@ -6,6 +6,7 @@ buildscript { dependencies { classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3' + classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.6.1" classpath 'org.sonatype.aether:aether-api:1.13.1' classpath 'org.sonatype.aether:aether-impl:1.13.1' } @@ -18,6 +19,8 @@ plugins { // Ensures that source code is generated at an appropriate location. id 'net.ltgt.apt' version '0.19' apply false id 'com.bmuschko.docker-java-application' version '4.0.4' apply false + id 'net.ltgt.errorprone' version '0.6.1' + id 'checkstyle' } apply from: 'dependencies.gradle' @@ -104,6 +107,27 @@ subprojects { apply plugin: 'nebula.dependency-lock' apply plugin: 'nebula.lint' apply plugin: 'net.ltgt.apt' + apply plugin: 'net.ltgt.errorprone' + apply plugin: 'checkstyle' + + // Checkstyle should run as part of the testing task + tasks.test.dependsOn tasks.checkstyleMain + tasks.test.dependsOn tasks.checkstyleTest + + dependencies { + // compatibility with Java 8 + errorproneJavac("com.google.errorprone:javac:9+181-r4173-1") + errorprone("com.google.errorprone:error_prone_core:2.3.2") + } + + tasks.withType(JavaCompile).configureEach { + options.compilerArgs << "-Werror" + options.errorprone.disableWarningsInGeneratedCode = true + options.errorprone.errorproneArgumentProviders.add([ + asArguments: { + return ['-XepExcludedPaths:.*/build/generated/.*'] + }] as CommandLineArgumentProvider) + } version = '1.0' sourceCompatibility = '1.8' diff --git a/gradle/config/checkstyle/checkstyle.xml b/gradle/config/checkstyle/checkstyle.xml new file mode 100644 index 000000000..5e8d60967 --- /dev/null +++ b/gradle/config/checkstyle/checkstyle.xml @@ -0,0 +1,251 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gradle/config/checkstyle/suppressions.xml b/gradle/config/checkstyle/suppressions.xml new file mode 100644 index 000000000..549987a53 --- /dev/null +++ b/gradle/config/checkstyle/suppressions.xml @@ -0,0 +1,12 @@ + + + + + + + + + +