Eclipse Checkstyle Plugin showin different results that maven-checkstyle-plugin

555 Views Asked by At

Recently I am trying to configure Checkstyle on Jenkins (which is using maven checkstyle results). My problem is that eclipse checkstyle is showing different number of checkstyle violations. I am using the same xml file with checkstyle rules for both maven and eclipse.

Eclipse Checkstyle Plugin 8.12.0 - ~500 violations maven-checkstyle-plugin 3.0.0 - over 5000 violations

For eclipse errors I can see mostly NPath Complexity and "String appears X times in the file" warnings.

For Maven chekstyle 2000 warnings are "Line has trailing spaces" (No such warning in eclipse). There are also many ConstantNameCheck, RegexpSinglelineJavaCheck, VisibilityModifierCheck warnings.

I assume that both plugins works differently, but is there any way to make it show similar warnings?

For Example: In simple project module I got 4 eclipse violations for NPath complexity. For file TestHandler.java it is showing "NPath Complexity is 13 allowed is 8". In maven I got 6 violations and most of them are different. Only similar one is saying that the same phrase in TestHandler.java "NPath Complexity is 13 allowed is 4".

This is how checking compexity looks in xml that both checkstyles are using:

</module>
<module name="CyclomaticComplexity">
  <property name="max" value="6" />
</module>
<module name="NPathComplexity">
  <property name="max" value="8" />
</module>

I run maven chestyle just by using mvn clean install checkstyle:checkstyle or on jenkis. I am using most basic confuration of maven plugin in pom. More information can be provided if needed.

1

There are 1 best solutions below

1
On

I did changes in the main pom as you proposed. I also removed Javadoc violations from checkstyle.xml file. Currently on eclipse I got ~510, on Intelij ~3100 and in Maven checkstyle ~ 3800. As I checked there are differences in violations on each of these three. This is snippet of my POM configuration for checkstyle:

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-checkstyle-plugin</artifactId>
      <version>3.0.0</version>
      <dependencies>
        <dependency>
          <groupId>com.puppycrawl.tools</groupId>
          <artifactId>checkstyle</artifactId>
          <version>6.18</version>
        </dependency>
      </dependencies>
      <executions>
      <execution>
      <id>validate</id>
      <phase>validate</phase>
      <configuration>
        <configLocation>common\code-style\checkstyle2.xml</configLocation>
        <encoding>UTF-8</encoding>
        <consoleOutput>true</consoleOutput>
        <failsOnError>true</failsOnError>
      </configuration>
        <goals>
          <goal>check</goal>
        </goals>
      </execution>
      </executions>
    </plugin>