eclipse Checkstyle - 排除文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18013322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Checkstyle - Exclude folder
提问by Philipp Sander
I want to ignore a specific folder (named generated-sources) from my checkstyle reports, because they are generated.
我想从我的 checkstyle 报告中忽略一个特定的文件夹(名为generated-sources),因为它们是生成的。
I'm using eclipse-cs for displaying my violations.
我正在使用 eclipse-cs 来显示我的违规行为。
i added a suppressionfilter to my xml:
我在我的 xml 中添加了一个抑制过滤器:
<module name="SuppressionFilter">
<property name="file" value=".\suppressions.xml"/>
</module>
my suppressions.xml looks like this:
我的pressions.xml 看起来像这样:
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<suppress files="\*generated-sources\*\*\.\*" checks="[a-zA-Z0-9]*"/>
</suppressions>
but it is not working. any ideas?
但它不起作用。有任何想法吗?
回答by Philipp Sander
<suppress files="[\/]generated-sources[\/]" checks="[a-zA-Z0-9]*"/>
this works :)
这有效:)
回答by Thomas Welsch
Additionally to the answer from Philipp, I had to use an absolute pathname ( :-( ) for the suppression file:
除了 Philipp 的回答之外,我还必须对抑制文件使用绝对路径名 (:-():
<module name="SuppressionFilter">
<property name="file" value="/Users/xxx/workspace/suppressions.xml"/>
</module>
Looks like the Checkstyle plugin is not using the project home directory.
看起来 Checkstyle 插件没有使用项目主目录。
(at least under eclipse luna / Mac OS X)
(至少在 eclipse luna / Mac OS X 下)
回答by gilad
As pointed by Thomas Welschin his answer, there appears to be a problem with using relative pathname for the suppression xml file.
正如Thomas Welsch在他的回答中指出的那样,对抑制 xml 文件使用相对路径名似乎存在问题。
For gradle builds, This gistsuggests a workaround:
对于 gradle 构建,此要点建议了一种解决方法:
in build.gradle
:
在build.gradle
:
checkstyle {
// use one common config file for all subprojects
configFile = project(':').file('config/checkstyle/checkstyle.xml')
configProperties = [ "suppressionFile" : project(':').file('config/checkstyle/suppressions.xml')]
}
in checkstyle.xml
:
在checkstyle.xml
:
<module name="SuppressionFilter">
<property name="file" value="${suppressionFile}" default="suppressions.xml"/>
</module>
(the default value allows IDE plugins, that do not have the gradle variable sorted out, to work correctly)
(默认值允许没有整理 gradle 变量的 IDE 插件正常工作)