我是 Maven 和 chekstyle 的新手,所以需要问一些问题...我想在我的基于 Maven 的项目中使用 checkstyle,所以在我的 pom.xml
中我添加了依赖项
<dependency>
<groupId>checkstyle</groupId>
<artifactId>checkstyle</artifactId>
<version>2.4</version>
</dependency>
我还在插件标签中添加了条目:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.4</version>
<configuration>
<enableRulesSummary>true</enableRulesSummary>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugin>
但是当我使用命令 mvn clean install
运行我的 Maven 构建时,checkstyle 不执行任何操作。由于我的系统中还没有任何 checkstyle.xml
,它不应该向我提示该错误吗?
我还缺少什么配置?
最佳答案
I want to use checkstyle in my maven based project, so in my pom.xml I've add the dependency (...)
你不需要添加这个依赖,你只需要声明插件(一个插件声明它自己的依赖)。
(...) But when I run my maven build with command mvn clean install, checkstyle doesn't do anything.
是的,因为您只声明插件,所以您没有绑定(bind) check
目标是生命周期阶段,因此正常构建不会触发 checkstyle 插件。如果你想要checkstyle:check
要作为构建的一部分触发,您需要声明 check
执行中的目标(默认情况下将自身绑定(bind)到 verify
阶段)。像这样的事情:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<!-- Lock down plugin version for build reproducibility -->
<version>2.5</version>
<configuration>
<consoleOutput>true</consoleOutput>
<configLocation>checkstyle.xml</configLocation>
...
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
现在,调用任何阶段,包括 verify
将调用 checkstyle。
And as I don't have any checkstyle.xml in my system yet, shouldn't it complains me about the error?
它将...在调用时(通过 mvn checkstyle:check
显式调用,或者如果您按照建议修改设置,则作为构建的一部分)。
关于maven-2 - 检查样式不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2747395/