javaformattingcode-formattingcheckstyle

How To Exclude Some Files From Checking Operations


I am using checkstyle plugin to format my code and I need to exclude some java classes from checking operations. To do that, I wrote the code below:

<module name="BeforeExecutionExclusionFileFilter">
    <property name="fileNamePattern" value="src/main/java/package1/*.java"/>
</module>

<module name="BeforeExecutionExclusionFileFilter">
    <property name="fileNamePattern" value="src/main/java/package2/*.java"/>
</module>

I tried to exclude all classes in 2 different packages. But the code does not works unfortunately. I also tried as below:

<module name="BeforeExecutionExclusionFileFilter">
    <property name="fileNamePattern" value="src/main/java/package1/*.java"/>
    <property name="fileNamePattern" value="src/main/java/package2/*.java"/>
</module>

But this did not worked as well. The checkstyle plugin again checks all classes. How can I achieve this?


Solution

  • I found the solution after long tries. My format for giving a path was wrong. Correct format should be like this one:

        <module name="BeforeExecutionExclusionFileFilter">
        <property name="fileNamePattern" value="[/\\]src[/\\]main[/\\]java[/\\]package1"/>
        </module>
    
        <module name="BeforeExecutionExclusionFileFilter">
            <property name="fileNamePattern" value="[/\\]src[/\\]main[/\\]java[/\\]package2"/>
        </module>
    

    If we wanna give more than one package to ignore, this is the way we should do. Giving two property with same name does not work. Hope this helps to others.