如何将警告更改为错误而错误?

时间:2015-12-26 00:16:36

标签: java maven errorprone

当我运行mvn clean compile

   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <compilerId>javac-with-errorprone</compilerId>
      <forceJavacCompilerUse>true</forceJavacCompilerUse>
      <showDeprecation>true</showDeprecation>
      <showWarnings>true</showWarnings>
    </configuration>
    <dependencies>
      <dependency>
        <groupId>org.codehaus.plexus</groupId>
        <artifactId>plexus-compiler-javac-errorprone</artifactId>
        <version>2.6</version>
      </dependency>
      <dependency>
        <groupId>com.google.errorprone</groupId>
        <artifactId>error_prone_core</artifactId>
        <version>2.0.6</version>
      </dependency>
    </dependencies>
  </plugin>

我一直试图将MissingOverride作为错误启用,或者只是为了发出任何内容,对于初学者我需要更改什么以查看“警告”的输出然后我应该怎样做才能获得{ {1}}是错误的?

1 个答案:

答案 0 :(得分:3)

plexus-compiler-javac-errorprone似乎没有输出警告的错误,但要将MissingOverride转换为错误,您可以将-Xep:MissingOverride:ERROR标志传递给编译器,如下:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
        <compilerId>javac-with-errorprone</compilerId>
        <forceJavacCompilerUse>true</forceJavacCompilerUse>
        <source>1.8</source>
        <target>1.8</target>
        <compilerArgs>
            <arg>-Xep:MissingOverride:ERROR</arg>
        </compilerArgs>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-compiler-javac-errorprone</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>com.google.errorprone</groupId>
            <artifactId>error_prone_core</artifactId>
            <version>2.0.7</version>
        </dependency>
    </dependencies>
</plugin>