排除 Maven Checkstyle 插件报告中的类
我有一个 Maven 2 项目,我想配置我的 Checkstyle 报告插件,以便只分析我的一些类。我找到了 maven.checkstyle.excludes 属性,但尽管将其作为命令行参数传递(使用 -D=maven.checkstyle.excludes=... )我无法让它工作。我在插件文档页面上找不到任何内容。理想情况下,我希望能够在 POM 的
部分中进行设置。
I have a Maven 2 project and I want to configure my Checkstyle report plugin so that only some of my classes are analysed. I have found the maven.checkstyle.excludes
property, but despite passing this as a command line parameter (using -D=maven.checkstyle.excludes=...
) I can't get it to work. I can't find anything on the Plugin documentation page. Ideally I want to be able to set this in the <configuration>
section of my POM.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果像我一样,您来到这里寻找一种从 checkstyle 中排除生成的源的方法,请执行以下操作:
默认情况下,
checkstyle:checkstyle
checkstyle 插件的目标使用${project.compileSourceRoots}
,显然包括生成的源目录。如果将其更改为
${project.build.sourceDirectory}
,它将仅使用源目录,而不使用任何生成的源目录。请注意,虽然
已弃用,但替代方案
似乎不起作用。编辑:在评论中,@Cyrusmith、@Ben 和 @Olivier Callioux 报告说,截至 2017 年,
有效;我无法确认。If, like me, you arrived here searching for a way to exclude generated sources from checkstyle, do this:
By default, the
checkstyle:checkstyle
goal of the checkstyle plugin uses${project.compileSourceRoots}
, which apparently includes generated source directories.If you change it to
${project.build.sourceDirectory}
, it will use only the source directory, not any generated source directories.Note that while
<sourceDirectory>
is deprecated, the alternative,<sourceDirectories>
, does not appear to work.Edit: In comments, @Cyrusmith, @Ben, and @Olivier Callioux report that as of 2017,
<sourceDirectories>
works; I cannot confirm.如果这个问题是关于 Maven 2,那么属性是 < code>excludes 并采用逗号分隔的 Ant 模式列表。因此,要么在命令行上传递它:
要么在插件配置中设置它:
另一个选择是使用 抑制过滤器。
例如,您可以使用
SuppressionCommentFilter
来抑制包含CHECKSTYLE:OFF
的注释和包含CHECKSTYLE:ON
的注释之间的审核事件 /em> (然后只需将这些注释添加到您不想检查的类或代码部分)。If this question is about Maven 2, then the property is
excludes
and takes a comma-separated list of Ant patterns. So either pass this on the command line:Or set it up in the plugin configuration:
Another option would be to use a suppression filter.
For example you could use the
SuppressionCommentFilter
to suppress audit events between a comment containingCHECKSTYLE:OFF
and a comment containingCHECKSTYLE:ON
(then just add these comments to the classes or parts of the code you don't want to check).此外,如果您想排除多个独立文件夹,您可以添加多个独立路径,以逗号分隔,如下所示
Additionally, if you want to exclude multiple independent folders, you can add multiple independent paths comma separated like this
上面的答案对我不起作用,因为我在 Maven 中运行代码生成,它还将目标/生成添加为源目录。
以下解决方案有效:
您必须使用显式的 checkstyle-suppressions.xml 配置文件并从配置中激活它:
用于排除目标文件夹的抑制文件如下所示:
The answers above didn't work for me as I'm running code generation in maven which also adds the target/generated as a source dir.
The following solution works:
You have to use an explicit checkstyle-suppressions.xml config file and activate it from your configuration:
The suppressions file for excluding the target folder looks like this:
我正在使用 maven 3 并且排除似乎不起作用。有效的是 sourceDirectories 技巧:
I'm using maven 3 and excludes does not seem to work. What worked was the sourceDirectories trick:
我正在使用 maven 3,但由于某种原因,排除和 sourceDirectory 都不起作用。为面临同样问题的任何人添加替代方案。
设置自定义检查样式抑制,如下所示。
在抑制文件中使用以下内容来排除特定文件。
I'm using maven 3 and both excludes and sourceDirectory did not work for some reason. Adding an alternative for anybody who is facing the same issue.
Setup a custom checkstyle suppression as shown below.
Use the following in the suppression file to exclude specific files.