问题描述
我是Maven和chekstyle的新手,所以需要问一些问题...我想在基于Maven的项目中使用checkstyle,所以在我的 pom.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>
但是当我使用命令 mvn clean install运行我的maven版本
,checkstyle不会执行任何操作。而且由于我的系统中还没有任何 checkstyle.xml
,它不应该向我抱怨该错误吗?
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?
我还缺少什么配置?
推荐答案
您无需添加此依赖,您只需要声明插件(插件声明了自己的依赖)。
You don't need to add this dependency, you just need to declare the plugin (a plugin declares its own dependencies).
是的,因为您仅已声明插件,您没有绑定的目标是生命周期阶段,因此常规构建不会触发checkstyle插件。如果您要在构建过程中触发 checkstyle:check
,则需要在 check
目标中声明目标执行(默认情况下,它会绑定到 verify
阶段)。像这样:
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 want checkstyle:check
to be triggered as part of your build, you need to declare the check
goal inside an execution (it binds itself by default to the verify
phase). Something like this:
<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
的阶段
Now, calling any phase including verify
will invoke checkstyle.
它将在调用时...(由 mvn checkstyle:check $ c $明确指定) c>或作为构建的一部分(如果您根据建议修改设置)。
It will... when called (either explicitly by mvn checkstyle:check
or as part of the build if you modify your setup as suggested).
这篇关于Checkstyle不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!