Reputation: 2787
I am trying to add in the maven-checkstyle-plugin
like below as part of build check by following the official documentation. However I try, I couldn't get it to run with custom rules.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The checkstyle.xml
just contains the exact content as found in this google_checks.xml.
Upon executing mvn checkstyle:check
, I always got hit by
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.0:check (default-cli) on project XXXXXXX: Failed during checkstyle configuration: cannot initialize module LineLength - Property 'fileExtensions' does not exist, please check the documentation
Upvotes: 2
Views: 3971
Reputation: 22706
The issue here is that the latest, v3.1.0 maven-checkstyle-plugin supports only the checkstyle
version v8.19:
This version of the plugin uses Checkstyle 8.19 by default and requires Java 8. But you can upgrade the version used at runtime.
So you need to use the checkstyle.xml
which belongs to v9.19 checkstyle
.
But the good news is that you can re-configure the maven plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>...choose your version...</version>
</dependency>
</dependencies>
</plugin>
For more details, check the official documentation.
Upvotes: 4
Reputation: 480
Just having the same problem. I see that the file have been changed 5 days ago.
You need to use file from the same version of checkstyle i.e for example for version 8.12 of checkstyle choose on git the branch with tag 8.12
https://github.com/checkstyle/checkstyle/blob/checkstyle-8.12/src/main/resources/google_checks.xml
This file have the correct grammar definition for version 8.12 , last version of same file for example don't work with 8.12 version
Hope it help :)
Upvotes: 8