I am injecting checkstyle maven plugin in my Java project. And I have one problem. The problem is that the plugin checks for a style license, which is placed inside the source code file.
What gives me an error:
[ERROR] src/main/java/io/github/eocqrs/kafka/consumer/KfConsumer.java:[11] (sizes)
LineLength: Line is longer than 80 characters (found 81).
How do I turn off the license block check?
So, I found a solution, not without the help of comments.
The first thing I had to do was to determine which block I needed to exclude for the test. In my case it was from line 0 to line 23. Then I had to create a file checkstyle-suppressions.xml
which would look like this
<?xml version="1.0"?
<!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN" "https://checkstyle.org/dtds/suppressions_1_0.dtd">
<suppressions>
<suppress checks="LineLength" files=".*\.java$" lines="0-23"/>
...
</suppressions>
In it I've listed all the checks I wanted to exclude for the license block. Also to check only Java sources I specified with regex file type - .*\.java$
.
Next, in project pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>verify-style</id>
<phase>process-classes</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
</configuration>
</execution>
</executions>
</plugin>
I specified the suppressionsLocation
configuration file I needed and the required suppressionsFileExpression
setting