java Maven 检查样式作为构建的一部分
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12180765/
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
Maven check style as a part of the build
提问by Paulius Matulionis
Is there a possibility to somehow force maven to fail the build if there are some checkstyle
errors? Now I have to run site
goal to generate javadocs
and checkstyle
reports. I want to make it on install
goal and if checkstyle has some error I need build to fail. Is this possible to achieve?
如果出现一些checkstyle
错误,是否有可能以某种方式强制 maven 使构建失败?现在我必须运行site
目标来生成javadocs
和checkstyle
报告。我想实现install
目标,如果 checkstyle 有一些错误,我需要构建失败。这有可能实现吗?
Now I have my checkstyle
in reporting block of maven:
现在我有我checkstyle
的 maven 报告块:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<configLocation>src/test/resources/checkstyle.xml</configLocation>
</configuration>
</plugin>
</plugins>
</reporting>
回答by hgrey
You need to bind checkstyle:check
to a Maven lifecycle phase (e.g. validate ) and set failOnViolation
to true.
您需要绑定checkstyle:check
到 Maven 生命周期阶段(例如 validate )并设置failOnViolation
为 true。
Something like:
就像是:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>checkstyle</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<failOnViolation>true</failOnViolation>
</configuration>
</execution>
</executions>
</plugin>
回答by JChrist
It might have been some time since the question was asked, but this wasn't working for me.
问这个问题可能已经有一段时间了,但这对我不起作用。
For anyone else that might be having the same issue as me, with the build succeeding despite a multitude of issues, I fixed it by lowering the violationSeverity
property from its default error
to warning
in the plugin's configuration
block.
对于可能与我有相同问题的其他任何人,尽管存在许多问题,但构建仍成功,我通过将violationSeverity
属性从默认值降低error
到warning
插件configuration
块中来修复它。
回答by Garret Fick
Even though it has been a long time since this was asked, I did run into another problem:
尽管已经很长时间没有提出这个问题了,但我确实遇到了另一个问题:
JavadocMethod: Unable to get class information for @throws tag 'X'.
JavadocMethod: Unable to get class information for @throws tag 'X'.
I solved this by changing the phase from "validate" to "test" so that checkstyle runs after the compile phase.
我通过将阶段从“验证”更改为“测试”来解决这个问题,以便在编译阶段之后运行 checkstyle。