Checkstyle不起作用 [英] Checkstyle not working

查看:302
本文介绍了Checkstyle不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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?

我还缺少什么配置?

推荐答案


我想在基于Maven的基础上使用checkstyle项目,因此在我的pom.xml中,添加了依赖项(...)

I want to use checkstyle in my maven based project, so in my pom.xml I've add the dependency (...)

您无需添加此依赖,您只需要声明插件(插件声明了自己的依赖)。

You don't need to add this dependency, you just need to declare the plugin (a plugin declares its own dependencies).


(...)但是当我运行使用命令mvn clean install进行maven构建,checkstyle不会执行任何操作。

(...) But when I run my maven build with command mvn clean install, checkstyle doesn't do anything.

是的,因为您仅已声明插件,您没有绑定 check 的目标是生命周期阶段,因此常规构建不会触发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.


而且由于我的系统中还没有任何checkstyle.xml,它是否应该向我抱怨该错误?

And as I don't have any checkstyle.xml in my system yet, shouldn't it complains me about the error?

它将在调用时...(由 mvn checkstyle:check 或作为构建的一部分(如果您根据建议修改设置)。

It will... when called (either explicitly by mvn checkstyle:check or as part of the build if you modify your setup as suggested).

这篇关于Checkstyle不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆