使用自定义Checkstyle运行Maven Checkstyle

Kev*_*ith 6 checkstyle maven

我跑了mvn checkstyle:checkstyle,但它没有使用我的自定义checkstyle XML文件.

请告诉我如何使用我自己的checkstyle文件,而不是默认/其中配置的任何一个?

Blu*_*ell 6

现在已针对最新版本的CheckStyle进行了更改,您需要使用属性声明文件位置:

<project
  xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  ...

  <properties>
    <checkstyle.config.location><!-- Specify file here --></checkstyle.config.location>
  </properties>

  <build>
    ...

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.9.1</version>
      </plugin>
    </plugins>
  </build>

</project>
Run Code Online (Sandbox Code Playgroud)

从我的如何编写自定义checkstyle检查的示例中获取:

http://blog.blundellapps.co.uk/create-your-own-checkstyle-check/

和源代码在这里:

https://github.com/blundell/CreateYourOwnCheckStyleCheck


Dun*_*nes 5

您需要在中配置文件位置pom.xml

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-checkstyle-plugin</artifactId>
      <version>2.9.1</version>  
      <configuration>
        <configLocation><!-- Specify file here --></configLocation>
      </configuration>
    </plugin>  
  </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

检查此页面以查看其他配置选项。