Search code examples
maven-checkstyle-plugin

maven-checkstyle-plugin does not execute on custom rules


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

Solution

  • 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 :)