Hi I am running checkstyle in a maven build. We have lots of generated code that we do not want checkstyle to be run on, as we don't care if the generated code does not conform to our style, and additionally, the number of checkstyle violations (40,000+ per plugin with generated files) makes running checkstyle take forever.
We added file suppression to the maven checkstyle configuration, and seems to work, as instead of reporting 40,000+ violations on our generated code it reports 0. However, it still seems to take quite a long time when running on the plugins with the generated code.
Which leads me to wonder, does adding file suppression actually prevent checkstyle from running on those files, or does it just prevent checkstyle from reporting the violations? If it is the latter, is there any way to completely prevent checkstyle from running on certain files? We would really like to reduce our checkstyle runtime as it currently takes more than 5 hours to run.
Thanks
Yes, you are right, checkstyle suppressions only prevent the logging of the violations and not the execution of the checkers.
You can use the BeforeExecutionExclusionFileFilter module in your checkstyle configuration to exclude files from processing.
Or alternatively you can configure the exclusion within the maven-checkstyle-plugin
using the excludes
configuration parameter.
For example the following configuration will exclude all the java source files ending with "Generated":
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.group</groupId>
<artifactId>checkstyle-test</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<excludes>**\/*Generated.java</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>