Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 342
Kevin Meredith Avatar asked Oct 10 '12 16:10

Kevin Meredith


2 Answers

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.

like image 126
Duncan Jones Avatar answered Oct 08 '22 03:10

Duncan Jones


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

like image 42
Blundell Avatar answered Oct 08 '22 03:10

Blundell