CheckStyle检查未被忽略 [英] CheckStyle checks not been ignored
问题描述
我已在我的pom.xml中设置了checkstyle检查,如下所示
I have set up my checkstyle checks in my pom.xml as follows
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.10</version>
<configuration>
<suppressionsLocation>
checkstyle-suppressions.xml
</suppressionsLocation>
<suppressionsFileExpression>
checkstyle-suppressions.xml
</suppressionsFileExpression>
</configuration>
</plugin>
</plugins>
</reporting>
我的checkstyle-supressions.xml文件包含以下内容
my checkstyle-supressions.xml file contains the following
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
<suppressions>
<suppress checks="JavadocStyleCheck"
files="**/*.java"
/>
<suppress checks="JavadocTypeCheck"
files="**/*.java"
/>
<suppress checks="JavadocVariableCheck"
files="**/*.java"
/>
<suppress checks="FileTabCharacterCheck"
files="**/*.java"
/>
</suppressions>
我希望在运行mvn网站时,检查样式插件不会报告任何JavaDoc注释或错误与制表符有关。但这不起作用。我怎样才能实现这个目标?
I want that when i run mvn site, the check style plugin does not report any JavaDoc comments or errors relating to tab characters. But this does not work. How can i achieve this ?
亲切的问候
推荐答案
< a href =http://checkstyle.sourceforge.net/config.html =nofollow> CheckStyle:SuppressionFilter 告诉我们
一个抑制XML文档包含一组
suppress
元素,其中每个suppress
元素可以包含以下属性:
A suppressions XML document contains a set of
suppress
elements, where eachsuppress
element can have the following attributes:
- 文件 - 正则表达式 与审核事件关联的文件名匹配。这是强制性的。
- 检查 - 正则表达式 与相关的检查名称相匹配审计事件。如果指定了id,则为可选。
- id - 与审核事件关联的检查的ID匹配的字符串。如果指定了支票,则可选。
- 行 - 以逗号分隔的值列表,其中每个值都是 一个整数 或由整数整数表示的整数范围。它是可选的。
- 列 - 以逗号分隔的值列表,其中每个值都是 一个整数 或由整数整数表示的整数范围。它是可选的。
- files - a regular expression matched against the file name associated with an audit event. It is mandatory.
- checks - a regular expression matched against the name of the check associated with an audit event. Optional if id is specified.
- id - a string matched against the id of the check associated with an audit event. Optional if checks is specified.
- lines - a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer. It is optional.
- columns - a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer. It is optional.
由于文件
是一个正则表达式
,您可以在 Java的正则表达式测试页。
Since the files
is a regular expression
, you can test the configure online at Regular Expression Test Page for Java.
如果文件
是 ** / * .java
,当使用 com.test.My.java应用
结果失败,因为正则表达式
时在索引0 ** / *附近悬挂元字符'*'。java ^
然后解决方案将文件
设置为。* \ .java
,当使用 com.test.My.java
应用正则表达式
时,结果为匹配():是, lookingAt():是, find():是和 group(0):com.test.My.java 。
Then the solution is setting the files
as .*\.java
, when apply the regular expression
with com.test.My.java
the result is matches(): yes, lookingAt(): yes, find(): yes and group(0): com.test.My.java.
插件配置应如下: -
The plugin configuration should be the following:-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.10</version>
<configuration>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
</configuration>
</plugin>
-
suppressionsLocation :指定要使用的抑制XML文件的位置。
此参数已解析为资源,网址,然后是文件。如果成功解析,则抑制XML的内容将被复制到$ {project.build.directory} /checkstyle-supressions.xml
文件中,然后传递给Checkstyle进行加载。
suppressionsLocation: Specifies the location of the suppressions XML file to use. This parameter is resolved as resource, URL, then file. If successfully resolved, the contents of the suppressions XML is copied into the
${project.build.directory}/checkstyle-supressions.xml
file before being passed to Checkstyle for loading.
suppressionsFileExpression 要在抑制文件的属性中使用的键。 默认值为: checkstyle.suppressions.file 。
suppressionsFileExpression The key to be used in the properties for the suppressions file. Default value is: checkstyle.suppressions.file.
请参阅 Maven Checkstyle插件:使用抑制过滤器了解更多信息。
我希望这可能有所帮助。
I hope this may help.
这篇关于CheckStyle检查未被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!