Kevin Meredith
Kevin Meredith

Reputation: 41939

Run Maven Checkstyle with Custom Checkstyle

I ran mvn checkstyle:checkstyle, but it's not using my custom checkstyle XML file.

Please advise me how to use my own checkstyle file rather than the default/whichever it's configured to now?

Upvotes: 13

Views: 17228

Answers (3)

Loginus
Loginus

Reputation: 449

If you want to run purely from commanline and do not modify your pom.xml run

mvn org.apache.maven.plugins:maven-checkstyle-plugin:3.4.0:check \ 
-Dcheckstyle.config.location=checkstyle_checks.xml \ 
-Dcheckstyle.suppressions.location=suppressions.xml

Where

  • checkstyle_checks.xml is a path to your configuration file
  • supressions.xml is a path to your supressions file

Upvotes: 1

Blundell
Blundell

Reputation: 76564

This has now changed for the latest version of CheckStyle, you need to declare the file location using a property:

<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>

Taken from my example of how to write a custom checkstyle check:

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

and the source code here:

https://github.com/blundell/CreateYourOwnCheckStyleCheck

Upvotes: 7

Duncan Jones
Duncan Jones

Reputation: 69409

You need to configure the file location in your 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>

Check the this page to see other configuration options.

Upvotes: 8

Related Questions