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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With