I am finding out ways to configure google_checks to use 4 spaces
in the maven Checkstyle plugin. I set the indentSize
configuration parameter to 4, but it does not work. Is there a configuration options to set this? I don't want to have my own version of google_checks.xml
just to have 4 spaces indent.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<dependencies>
<dependency>
<artifactId>checkstyle</artifactId>
<groupId>com.puppycrawl.tools</groupId>
<version>8.36.1</version>
</dependency>
</dependencies>
<configuration>
<configLocation>google_checks.xml</configLocation>
<indentSize>4</indentSize>
<failsOnError>true</failsOnError>
<consoleOutput>true</consoleOutput>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
Update: It seems like there is no way to have a single format that is compatible with maven-checkstyle-plugin
, Checkstyle with google_checks
and Intellij with google_java_format
. Has anyone been able to achieve this?
Overview
Currently, Checkstyle does not support such configuration composition.
Here are some of the related GitHub issues:
How to extend/override an existing configuration (sun, google) · Issue #4484 · checkstyle/checkstyle.
create concept of inheritance/override and compositions/extension of configs · Issue #2873 · checkstyle/checkstyle.
A workaround
There is a quite straightforward workaround to override some checks of a configuration file: split the single Checkstyle Maven plugin execution into two executions:
This workaround is also explained here: create concept of inheritance/override and compositions/extension of configs · Issue #2873 · checkstyle/checkstyle: The comment.
Indentation-related example (draft)
Project:
pom.xml
The
/build/pluginManagement/plugins
plugin definition:The
/build/plugins
plugin definition:Checkstyle configuration file:
maven-checkstyle-suppressions-google_checks.xml
Checkstyle configuration file:
maven-checkstyle-custom_checks.xml