Skip to content

Commit

Permalink
Support Error Prone on Java 8-11
Browse files Browse the repository at this point in the history
The previous Error Prone setup only properly worked on Java 8 and 9. By
configuring Error Prone as a javac plugin it now also successfully runs on Java
10 and above. Running the plugin under Java 8 requires a modest amount of extra
configuration.

While there:
- Enable the `ConstructorLeaksThis` check now that the bug that was filed
  against it is fixed.
- Drop the `-Xlint:-processing` flag because it seems the code now compiles
  fine without it.
  • Loading branch information
Stephan202 committed Sep 8, 2018
1 parent 3873856 commit 4c4c3dd
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 51 deletions.
11 changes: 3 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ matrix:
- jdk: openjdk9
script: ./mvnw install
- jdk: oraclejdk10
# XXX: On JDK 10 Error Prone causes warnings to be emitted; see
# https://github.com/google/error-prone/issues/860.
script: ./mvnw install -Dverification.warn
script: ./mvnw install
- jdk: openjdk10
# XXX: On JDK 10 Error Prone causes warnings to be emitted; see
# https://github.com/google/error-prone/issues/860.
script: ./mvnw install -Dverification.warn
script: ./mvnw install
- jdk: openjdk-ea
# XXX: Error Prone is not yet compatible with JDK 11.
script: ./mvnw install -Dverification.skip
script: ./mvnw install
addons:
sonarcloud:
organization: picnic-technologies
Expand Down
122 changes: 79 additions & 43 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.error-prone>2.3.1</version.error-prone>
<version.error-prone-javac>9+181-r4173-1</version.error-prone-javac>
<version.guava-beta-checker>1.0</version.guava-beta-checker>
<version.javadoc>3.0.1</version.javadoc>
<version.jdk>1.8</version.jdk>
<version.maven>3.5.3</version.maven>
<version.nullaway>0.5.5</version.nullaway>
<version.plexus-compiler>2.8.5</version.plexus-compiler>
<version.surefire>2.22.0</version.surefire>
<!-- Our build system (Travis CI) provides a monotonically increasing
build number. When building locally, this number is obviously absent.
Expand Down Expand Up @@ -132,16 +132,27 @@
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<!-- Specified as a workaround for
https://github.com/mojohaus/versions-maven-plugin/issues/244. -->
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${version.error-prone}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>26.0-jre</version>
</dependency>
<!-- Specified as a workaround for
https://github.com/mojohaus/versions-maven-plugin/issues/244. -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-beta-checker</artifactId>
<version>${version.guava-beta-checker}</version>
</dependency>
<!-- Specified as a workaround for
https://github.com/mojohaus/versions-maven-plugin/issues/244. -->
<dependency>
<groupId>com.uber.nullaway</groupId>
<artifactId>nullaway</artifactId>
Expand Down Expand Up @@ -772,6 +783,11 @@
</executions>
<configuration>
<annotationProcessorPaths combine.children="append">
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${version.error-prone}</version>
</path>
<path>
<groupId>com.google.guava</groupId>
<artifactId>guava-beta-checker</artifactId>
Expand All @@ -787,52 +803,35 @@
<!-- We enable nearly all doclint checks,
except that we don't care about missing Javadoc
on non-public classes and members. -->
<arg>-Xdoclint:all</arg>
<arg>-Xdoclint:missing/protected</arg>
<arg>-Xdoclint:all,-missing/package</arg>
<arg>-Xlint:all</arg>
<!-- Not all annotations present on the
classpath are handled by annotation processors,
and javac complains about this. That doesn't
make a lot of sense. From time to time we
should review whether this issue has been
resolved. -->
<arg>-Xlint:-processing</arg>
<!-- We want to enable almost all error-prone
bug pattern checkers, so we enable all and then
selectively deactivate some. -->
<arg>-XepAllDisabledChecksAsWarnings</arg>
<!-- See https://github.com/google/error-prone/issues/655. -->
<arg>-Xep:ConstructorLeaksThis:OFF</arg>
<!-- See https://github.com/google/error-prone/issues/708. -->
<arg>-Xep:FieldMissingNullable:OFF</arg>
<arg>-XepOpt:NullAway:AnnotatedPackages=tech.picnic</arg>
<!-- Enable and configure Error Prone. -->
<!-- XXX: The awkward comment formatting used
here ensures that the plugin arguments are
separated only by spaces. Once we drop support
for JDK 8 we can clean this up; later versions
do properly handle newline separators. See
https://github.com/google/error-prone/pull/1115. -->
<arg>
-Xplugin:ErrorProne <!--
We want to enable almost all Error
Prone bug pattern checkers, so we enable
all and then selectively deactivate some.
--> -XepAllDisabledChecksAsWarnings <!--
See https://github.com/google/error-prone/issues/708.
--> -Xep:FieldMissingNullable:OFF <!--
--> -XepOpt:NullAway:AnnotatedPackages=tech.picnic
</arg>
<!-- The Error Prone plugin makes certain
assumptions about the state of the AST at the
moment it is invoked. This can be ensured by
using the `simple` compile policy. This flag
may be dropped after resolution of
https://bugs.openjdk.java.net/browse/JDK-8155674. -->
<arg>-XDcompilePolicy=simple</arg>
</compilerArgs>
<compilerId>javac-with-errorprone</compilerId>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<showWarnings>true</showWarnings>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${version.error-prone}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-api</artifactId>
<version>${version.plexus-compiler}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac</artifactId>
<version>${version.plexus-compiler}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac-errorprone</artifactId>
<version>${version.plexus-compiler}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -860,6 +859,36 @@
</plugins>
</build>
</profile>
<profile>
<id>error-prone-on-jdk8</id>
<activation>
<jdk>1.8</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- When using JDK 8, the Error Prone plugin
requires that `javac` is forked so that a
custom boot classpath can be configured. (The
custom Error Prone `javac` referenced here is
resolved implicitly as a dependency of
`error_prone_core`; as such the JAR is
guaranteed to exist by the time the classpath
is consulted.) -->
<fork>true</fork>
<compilerArgs combine.children="append">
<arg>-J-Xbootclasspath/p:${settings.localRepository}/com/google/errorprone/javac/${version.error-prone-javac}/javac-${version.error-prone-javac}.jar</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profile>
<!-- The `build-checks` profile enables a whole bunch of additional
compile checks. By default those warnings break the build. This
Expand Down Expand Up @@ -899,6 +928,13 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs combine.children="append">
<!-- When using a JDK other than the one
specified using `-source`, `javac` warns
that the bootstrap classpath will not be
set. We don't want to fail on that warning. -->
<arg>-Xlint:-options</arg>
</compilerArgs>
<failOnWarning>true</failOnWarning>
</configuration>
</plugin>
Expand Down

0 comments on commit 4c4c3dd

Please sign in to comment.