Error-prone: Unable to use AllErrorsAsWarnings flag in Maven

Created on 12 Feb 2019  路  3Comments  路  Source: google/error-prone

Description of the problem / feature request:

I am unable to downgrade all errors to warnings using the '-XepAllErrorsAsWarnings' flag (as seen here)

When I run mvn compile without the flag, I (correctly) get the following error:

[ERROR] /Users/ccook/projects/test-app/src/main/java/com/testgroup/testapp/App.java:[15,8] error: [DeadException] Exception created but not thrown
    (see https://errorprone.info/bugpattern/DeadException)
  Did you mean to remove this line?

When I run with the flag, I get the following error:

[ERROR] javac: invalid flag: -XepAllErrorsAsWarnings
Usage: javac <options> <source files>
use --help for a list of possible options

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Run mvn compile in the same directory as the pom.xml in the unzipped test-app
test-app.zip

What version of Error Prone are you using?

2.3.2

I am also using Maven version 3.5.4 and Java version 1.8.0_181 on OS X (updated to Mojave).

Have you found anything relevant by searching the web?

Unfortunately not. I'm guessing I'm just doing something wrong, since nobody else seems to be having this issue.

Most helpful comment

I needed to add <showWarnings>true</showWarnings> to the maven-compiler-plugin configuration to get the warnings to show.

diff --git a/pom.xml b/pom.xml
index b5727d4..71c1aca 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,9 +33,10 @@
         <configuration>
           <source>8</source>
           <target>8</target>
+          <showWarnings>true</showWarnings>
           <compilerArgs>
             <arg>-XDcompilePolicy=simple</arg>
-            <arg>-Xplugin:ErrorProne</arg>
+            <arg>-Xplugin:ErrorProne -XepAllErrorsAsWarnings</arg>
           </compilerArgs>
           <annotationProcessorPaths>
             <path>

I think that's all I needed, thanks!

All 3 comments

You're hit by a Java 8-specific issue, described in #1115.

Possible fix:

diff --git a/pom.xml b/pom.xml
index 9e25de2..2a9030b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,8 +35,7 @@
           <target>8</target>
           <compilerArgs>
             <arg>-XDcompilePolicy=simple</arg>
-            <arg>-Xplugin:ErrorProne
-                 -XepAllErrorsAsWarnings</arg>
+            <arg>-Xplugin:ErrorProne -XepAllErrorsAsWarnings</arg>
           </compilerArgs>
           <annotationProcessorPaths>
             <path>

Or if you plan to add many more flags:

diff --git a/pom.xml b/pom.xml
index 9e25de2..77a6785 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,8 +35,8 @@
           <target>8</target>
           <compilerArgs>
             <arg>-XDcompilePolicy=simple</arg>
-            <arg>-Xplugin:ErrorProne
-                 -XepAllErrorsAsWarnings</arg>
+            <arg>-Xplugin:ErrorProne<!--
+            -->  -XepAllErrorsAsWarnings</arg>
           </compilerArgs>
           <annotationProcessorPaths>
             <path>

I tried the first fix. It did get rid of the error, but the compilation did not show the DeadException as a warning. Do I need to add another flag to get the warning to show?

I needed to add <showWarnings>true</showWarnings> to the maven-compiler-plugin configuration to get the warnings to show.

diff --git a/pom.xml b/pom.xml
index b5727d4..71c1aca 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,9 +33,10 @@
         <configuration>
           <source>8</source>
           <target>8</target>
+          <showWarnings>true</showWarnings>
           <compilerArgs>
             <arg>-XDcompilePolicy=simple</arg>
-            <arg>-Xplugin:ErrorProne</arg>
+            <arg>-Xplugin:ErrorProne -XepAllErrorsAsWarnings</arg>
           </compilerArgs>
           <annotationProcessorPaths>
             <path>

I think that's all I needed, thanks!

Was this page helpful?
0 / 5 - 0 ratings