使用Maven和Eclipse编译器编译Groovy:如何忽略未知的@SuppressWarnings?

时间:2020-05-15 13:24:33

标签: eclipse maven groovy

我有一个使用以下代码的Groovy代码的Maven项目:

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>${maven-compiler-plugin.version}</version>
      <extensions>true</extensions>
      <configuration>
        <source>${source.version}</source>
        <target>${source.version}</target>
        <verbose>false</verbose>
        <compilerId>groovy-eclipse-compiler</compilerId>
        <compilerArguments>
          <indy />
        </compilerArguments>
      </configuration>
      <dependencies>
        <dependency>
          <groupId>org.codehaus.groovy</groupId>
          <artifactId>groovy-eclipse-compiler</artifactId>
          <version>${groovy-eclipse-compiler.version}</version>
        </dependency>
        <dependency>
          <groupId>org.codehaus.groovy</groupId>
          <artifactId>groovy-eclipse-batch</artifactId>
          <version>${groovy-eclipse-batch.version}</version>
        </dependency>
        <dependency>
          <groupId>org.codehaus.groovy</groupId>
          <artifactId>groovy</artifactId>
          <version>${groovy.version}</version>
        </dependency>
        <dependency>
          <groupId>org.codehaus.groovy</groupId>
          <artifactId>groovy-json</artifactId>
          <version>${groovy.version}</version>
        </dependency>
        <dependency>
          <groupId>org.codehaus.groovy</groupId>
          <artifactId>groovy-templates</artifactId>
          <version>${groovy.version}</version>
        </dependency>
        <dependency>
          <groupId>org.codehaus.groovy</groupId>
          <artifactId>groovy-xml</artifactId>
          <version>${groovy.version}</version>
        </dependency>
        <dependency>
          <groupId>org.codehaus.groovy</groupId>
          <artifactId>groovy-json</artifactId>
          <version>${groovy.version}</version>
        </dependency>
        <dependency>
          <groupId>org.codehaus.groovy</groupId>
          <artifactId>groovy-templates</artifactId>
          <version>${groovy.version}</version>
        </dependency>
      </dependencies>
    </plugin>

(Maven属性在其他位置设置)

现在我们正在使用CodeNarc,有时会产生误报。为了抑制这种情况,我们使用@SuppressWarnings,例如@SuppressWarnings('GStringExpressionWithinString'),这反过来导致Eclipse编译器显示警告:

15:12:29.671 [WARNING] C:\groovy\src\main\groovy\Util.groovy:[472,19] 
7. WARNING in C:\groovy\src\main\groovy\Util.groovy (at line 472)
  @SuppressWarnings('GStringExpressionWithinString')
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

谁能告诉我如何配置Eclipse编译器以停止显示这些警告?

1 个答案:

答案 0 :(得分:0)

看起来像编译器选项-warn:-warningToken会禁用未使用的@SuppressWarnings令牌的警告。

https://help.eclipse.org/2020-03/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-using_batch_compiler.htm

https://github.com/groovy/groovy-eclipse/wiki/Groovy-Eclipse-Maven-plugin

  <configuration>
    <compilerId>groovy-eclipse-compiler</compilerId>
    <compilerArguments>
      <indy />
      <warn:-warningToken />
    </compilerArguments>
  </configuration>

https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#compilerArguments

否则,您可以切换为使用<compilerArgs>,它可以更好地控制每个参数字符串。

  <configuration>
    <compilerId>groovy-eclipse-compiler</compilerId>
    <compilerArgs>
      <arg>-indy</arg>
      <arg>-warn:-warningToken</arg>
    </compilerArgs>
  </configuration>
相关问题