Why checkstyle suppression rules through MAVEN CheckStyle Plugin is not working in Jenkins Build Step

135 views Asked by At

I have to use the checkStyle MAVEN plugin through pom.xml with Jenkins for a free-style java project and I want to suppress some rules such as the line length check. Everything is working fine with the invocation of command mvn clean verify site directly from command line but when I try the same thing via the Jenkins build step, Jenkins ignores the suppressed rule and continues to check lines length.

I’m using MAVEN 3.9.0, maven-checkstyle-plugin 3.3.0 and Jenkins 2.387.3.

I created a checkstyle-suppressions.xml file in which I put the check to suppress and placed it in the same directory as pom.xml and sun_checks.xml.

checkstyle-suppressions.xml :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suppressions PUBLIC
    "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
    "https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
    <suppress files=".*" checks="LineLengthCheck"/>
</suppressions>

Part of pom.xml for checkstyle plugin:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<configLocation>sun_checks.xml</configLocation>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>checkstyle</report>
</reports>
<configuration>
<outputDirectory>${project.reporting.outputDirectory}/checkstyle-html</outputDirectory>
<outputName>checkstyle-report</outputName>
<outputFileFormat>plain</outputFileFormat>
<configLocation>sun_checks.xml</configLocation>
<enableFilesSummary>true</enableFilesSummary>
<enableSeveritySummary>true</enableSeveritySummary>
<enableRSS>true</enableRSS>
</configuration>
</reportSet>
</reportSets>
</plugin>

I even tried another way:

  1. added the module bellow to sun_checks.xml
<module name="SuppressionFilter">
<property name="file" value="mysuppressions.xml"/>
</module>
  1. created mysuppressions.xml with same content than checkstyle-suppressions.xml above :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suppressions PUBLIC
    "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
    "https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
    <suppress files=".*" checks="LineLengthCheck"/>
</suppressions>
  1. modified the pom.xml by suppressing the 2 lines for checkstyle-suppressions.xml invocation :
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>

=> Same result as the first method : working fine with command-line mvn clean verify site but Jenkins is still checking line length.

0

There are 0 answers