Creating a customized version of the Google Java Checkstyle XML file

2.1k views Asked by At

I am currently trying to create a checkstyle stylesheet that is based off of the Google one, but with some minor tweaks (new line length and indentation lengths. I grabbed this file off of Github (https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml), but I am getting the following error when I run it:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1:check (default-cli) on project some-api: Execution default-cli of goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1:check failed: given name COMPACT_CTOR_DEF -> [Help 1]

Maven plugin configuration:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>${checkstyle-maven-plugin.version}</version>
        <configuration>
          <consoleOutput>true</consoleOutput>
          <configLocation>google_checks1.xml</configLocation>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

Are there some dependencies that I need to include? Is there a better way of achieving my goal? Any feedback would be appreciated.

1

There are 1 answers

0
Rut the Nut On

The comment above gives the way to fix this issue. Need to include the dependency to specify the checkstyle version for the maven plugin.

The following worked for me, fixing the COMPACT_CTOR_DEF error from the copied google checks

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>3.1.1</version>
    <dependencies>
        <dependency>
            <groupId>com.puppycrawl.tools</groupId>
            <artifactId>checkstyle</artifactId>
            <version>8.36</version>
        </dependency>
    </dependencies>

    <configuration>
        <configLocation>my_checks.xml</configLocation>
    </configuration>
</plugin>