eclipse does not respect suppression.xml file from maven-checkstyle-plugin

83 views Asked by At

I've using the maven-checkstyle-plugin (config see below) in version 3.2.1 for quite some time now and I'm also using a custom checkstyle.xml and suppressions.xml

e.g. in the suppressions.xml I have entries like:

<suppress files="messages.properties" checks="[a-zA-Z0-9]*"/>
<suppress files="target/generated-sources" checks=".*"/>

Since a few days, I see an error message in my eclipse (2023-03), e.g. in the above mentioned message.properties file:

(!) Line is longer then 120 characters (found xxx)
my.lang.key = a very long line with more then 120 chars, but this file should be ignored at all ...

The generated code in target/generated-sources/... is also clustered with checkstyle errors, although the files in this path should not be validated.

If I run a build on the console the build does not fail, hence the plugin is respecting the suppression.xml file, but the error flag in eclipse is still shown.

An update to maven-checkstyle-plugin:3.2.2 and checkstyle:10.11.0 (currently most recent versions) did not fix the problem.

Just another observation, I also have a new meta/config file in my project: .checkstyle, I suppose this is related ...?

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.2.1</version>
<dependencies>
    <dependency>
        <groupId>acme</groupId>
        <artifactId>checkstyle-config-cms</artifactId>
        <version>1.2.0</version>
    </dependency>
    <dependency>
        <groupId>com.puppycrawl.tools</groupId>
        <artifactId>checkstyle</artifactId>
        <version>10.6.0</version>
    </dependency>
</dependencies>
<configuration>
    <configLocation>checkstyle.xml</configLocation>
    <suppressionsLocation>suppressions.xml</suppressionsLocation>
    <inputEncoding>UTF-8</inputEncoding>
    <consoleOutput>true</consoleOutput>
    <failsOnError>true</failsOnError>
    <linkXRef>false</linkXRef>
</configuration>
<executions>
    <execution>
        <id>validate</id>
        <phase>validate</phase>
        <goals>
            <goal>check</goal>
        </goals>
    </execution>
</executions>
</plugin>
1

There are 1 answers

0
morecore On

Unfortunately, until now I did not come up with a better solution then to disable the checkstyle plugin within eclipse.

To do so, right click your project -> Checkstyle -> Deactivate Checkstyle

If the error is still shown you must clear your checkstyle violations. The maven run is not affected by this change and still is using checkstyle correctly.


Update (2024/01/24):

As it turns out you can avoid this problem when importing a project into eclipse (I'm using currently version: 2023-12 - freshly installed).

When I import a clean maven project that is using the checkstyle-maven-plugin into eclipse. I get a pop-up asking to setup a maven plugin connector.

maven-checkstyle-connector plugin

Install Applies configuration from the maven-checkstyle-plugin to the Eclipse Checkstyle plugin. Disables execution of the maven-checkstyle-plugin within Eclipse in favor of the Eclipse plugin.

You probably can skip/cancel this, BUT if you are adding in advance some eclipse meta data information (see eclipse release-notes-17), e.g. <?m2e ignore?>

A new syntax has been introduced to simplify lifecycle mapping metadata for plugin executions, using processing instructions within plugin/executions/execution nodes.

Eclipse will not ask you to take control of the checkstyle handling and most probably will not make the above mentioned problems.

...
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-checkstyle-plugin</artifactId>
  <version>3.3.1</version>
  <?m2e ignore?>
  ...