简体   繁体   English

如何让maven在原始类型上失败?

[英]How to make maven fail on raw types?

I want to make maven compile fail if somewhere in the code, raw types (missing generics) are used. 我想在代码中的某处使用maven编译失败,使用原始类型(缺少泛型)。 I tried the following: 我尝试了以下方法:

  1. The javac does not recognize these errors (the eclipse compiler does); javac不识别这些错误(eclipse编译器会这样做); Starting from version 7, the -Xlint:rawtypes parameter to javac can be used to issue warnings if raw types are used. 从版本7开始,如果使用原始类型,则可以使用-Xlint:rawtypes参数到javac发出警告。 Unfortunately, I have to use java 6 which does not support this flag. 不幸的是,我必须使用不支持此标志的java 6。
  2. CheckStyle has no rules for such things. CheckStyle没有针对此类事情的规则。
  3. PMD also has no abilities to check for raw types. PMD也没有检查原始类型的能力。

Are there any other maven-modules or tricks which generate an error if raw types are used? 如果使用原始类型,是否还有其他maven模块或技巧会产生错误?

I don't know if it would help, but you can use the eclipse compiler in maven 我不知道它是否会有所帮助,但你可以在maven中使用eclipse编译器

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <version>2.3.2</version>
   <configuration>
      <compilerId>eclipse</compilerId>
      <source>1.6</source>
      <target>1.6</target>
   </configuration>
   <dependencies>
      <dependency>
         <groupId>org.codehaus.plexus</groupId>
         <artifactId>plexus-compiler-eclipse</artifactId>
         <version>1.8.2</version>
      </dependency>
   </dependencies>
</plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM