Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude module-info.java from checkstyle plugin checks?

After adding module-info.java files to my project my checkstyle plugin start failing with:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (default-cli) on project email: Failed during checkstyle configuration: NoViableAltException occurred during the analysis of file /home/xxx/IdeaProjects/blynk-server/server/notifications/email/src/main/java/module-info.java. unexpected token: module -> [Help 1]

I tried

<module name="BeforeExecutionExclusionFileFilter">
    <property name="fileNamePattern" value="module\-info\.java$"/>
</module>

However, it failed with:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (default-cli) on project blynk: Failed during checkstyle configuration: cannot initialize module BeforeExecutionExclusionFileFilter - Unable to instantiate 'BeforeExecutionExclusionFileFilter' class, it is also not possible to instantiate it as com.puppycrawl.tools.checkstyle.checks.annotation.BeforeExecutionExclusionFileFilter

What is the correct way for skipping module-info.java files during checkstyle for maven-checkstyle-plugin?

like image 883
Dmitriy Dumanskiy Avatar asked Sep 29 '17 19:09

Dmitriy Dumanskiy


People also ask

How do you get a Checkstyle violation?

It will also generate the violation report for the project which is available as a view in Eclipse. To view to violation report, go to Window -> Show View -> Other, and search for Checkstyle. Options for Violations and Violations Chart should be displayed.

Is Checkstyle a Linter?

Checkstyle is one of the most popular linters available. With this popularity comes regular updates, thorough documentation, and ample community support.


1 Answers

Not sure why the Checkstyle filter is not working (this reported bug seems very similar to yours and it was fixed in version 7.3.0, so maybe you need to update Checkstyle).

Anyway the Maven excludes element is also supposed to do this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <configuration>
        <excludes>**/module-info.java</excludes>
    </configuration>
</plugin>

More in the plugin goal documentation.

like image 100
M A Avatar answered Sep 18 '22 19:09

M A