检查样式不起作用
我是 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 am new to maven and chekstyle, so need to ask some question... I want to use checkstyle in my maven based project, so in my pom.xml
I have add the dependency
<dependency>
<groupId>checkstyle</groupId>
<artifactId>checkstyle</artifactId>
<version>2.4</version>
</dependency>
and also I have added the entry in plugin tag:
<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>
But when I run my maven build with command mvn clean install
, checkstyle doesn't do anything. And as I dont have any checkstyle.xml
in my system yet, shouldn't it complains me about the error?
What else configuration am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不需要添加这个依赖项,你只需要声明插件(一个插件声明它的自己的依赖项)。
是的,因为您只声明插件,所以您没有绑定
check
目标是生命周期阶段,因此正常构建不会触发 checkstyle 插件。如果您希望checkstyle:check
作为构建的一部分被触发,您需要在执行中声明check
目标(它默认将自身绑定到验证阶段)。像这样:
现在,调用包括
verify
在内的任何阶段都将调用 checkstyle。它将...在调用时(通过
mvn checkstyle:check
显式调用,或者如果您按照建议修改设置,则作为构建的一部分)。You don't need to add this dependency, you just need to declare the plugin (a plugin declares its own dependencies).
Yes because you only declared the plugin, you did not bind the
check
goal to a lifecycle phase, so a normal build doesn't trigger the checkstyle plugin. If you wantcheckstyle:check
to be triggered as part of your build, you need to declare thecheck
goal inside an execution (it binds itself by default to theverify
phase). Something like this:Now, calling any phase including
verify
will invoke checkstyle.It will... when called (either explicitly by
mvn checkstyle:check
or as part of the build if you modify your setup as suggested).