我正在使用插件
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
它有6.11.2 checkstyle版本。关于空格的配置是:
<module name="NoWhitespaceAfter">
<property name="severity" value="error" />
<property name="tokens" value="ARRAY_INIT,BNOT,DEC,DOT,INC,LNOT" />
</module>
<module name="NoWhitespaceBefore">
<property name="severity" value="error" />
</module>
<module name="RedundantModifier">
<property name="severity" value="error" />
</module>
<module name="WhitespaceAround">
<property name="severity" value="error" />
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,DO_WHILE,EQUAL,GE,LAND,LCURLY,LE,LITERAL_ASSERT,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,TYPE_EXTENSION_AND" />
</module>
我总是收到这个错误:
(whitespace) WhitespaceAround: WhitespaceAround: '?' is not preceded with whitespace.
(whitespace) WhitespaceAround: WhitespaceAround: '?' is not followed by whitespace.
Empty blocks may only be represented as {} when not part of a multi-block statement (4.1.3)
代码段是:
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
我尝试删除带有空格的代码段,但仍然会收到相同的错误。
有人有同样的问题吗?
非常感谢!
答案 0 :(得分:4)
这是checkstyle中的一个错误,已在Checkstyle 6.14中修复(请参阅https://github.com/checkstyle/checkstyle/issues/2633)
您可以通过在maven-checkstyle-plugin中添加<dependencies>
部分来升级checkstyle:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>6.14</version>
</dependency>
</dependencies>
</plugin>
或者你可以直接进入最新的Checkstyle(7.0)。