'How to exclude packages from CheckStyle analysis in a mavenized multi-module project?

I have a Maven project with several modules, including org.eclipse.cdt.core. For some reason, the customer wants to build org.eclipse.cdt.core as well.

I want to generate an aggregated Checkstyle report, from which some files, including all org.eclipse.cdt.core.* (incl. subpackages) classes are excluded.

For this purpose, I specified the excludes tag as

<excludes>**/org/eclipse/cdt/core/**/*,org.eclipse.cdt.core/src/**/*,../org.eclipse.cdt.core/src/**/*,org.eclipse.cdt.core/**/*</excludes>

Then I ran mvn clean checkstyle-aggregate site, opened the file target/checkstyle-result.xml and found following lines in it:

<file name="C:\dev\ide\org.eclipse.cdt.core\src\org\eclipse\cdt\core\AbstractExecutableExtensionBase.java">
<error line="0" severity="error" message="File does not end with a newline." source="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck"/>
<error line="10" severity="error" message="Line is longer than 80 characters (found 81)." source="com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck"/>
<error line="15" severity="error" message="Line is longer than 80 characters (found 83)." source="com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck"/>

This means that my <excludes> tag doesn't work.

Then, I put the lines

<properties>
    <checkstyle.skip>true</checkstyle.skip>
</properties>

into pom.xml files of all modules to be excluded from Checkstyle, but it didn't help.

How can I generate a CheckStyle report (XML or HTML), without the results for certain modules (other than taking the 180 MB large target/checkstyle-result.xml and removing all "wrong" file enries from there) ?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>mycompany-parentproject</groupId>
    <artifactId>com.mycompany.parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <tycho-version>0.21.0</tycho-version>
        <tycho-extras-version>0.21.0</tycho-extras-version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <antrun-version>1.7</antrun-version>
    </properties>

    <pluginRepositories>
        <pluginRepository>
            <id>Codehaus repository</id>
            <url>http://repository.codehaus.org/</url>
        </pluginRepository>
    </pluginRepositories>

    <distributionManagement>
        <site>
            <id>${project.artifactId}-site</id>
            <url>${project.baseUri}</url>
        </site>
    </distributionManagement>
    <build>
        <plugins>
            <plugin>
                <!-- enable tycho build extension -->
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-maven-plugin</artifactId>
                <version>${tycho-version}</version>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>target-platform-configuration</artifactId>
                <version>${tycho-version}</version>
                <configuration>
                    <environments>
                        <environment>
                            <os>win32</os>
                            <ws>win32</ws>
                            <arch>x86_64</arch>
                        </environment>
                        <environment>
                            <os>win32</os>
                            <ws>win32</ws>
                            <arch>x86</arch>
                        </environment>
                        <environment>
                            <os>linux</os>
                            <ws>gtk</ws>
                            <arch>x86_64</arch>
                        </environment>
                        <environment>
                            <os>linux</os>
                            <ws>gtk</ws>
                            <arch>x86</arch>
                        </environment>
                    </environments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-versions-plugin</artifactId>
                <version>${tycho-version}</version>
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-packaging-plugin</artifactId>
                <version>${tycho-version}</version>
                <configuration>
                    <format>'mycompany_'yyyyMMddHHmm</format>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <modules>
        <module>../com.mycompany.module1</module>
        <module>../com.mycompany.module2</module>
        <module>../com.mycompany.module3</module>
        <module>../org.eclipse.cdt.core</module>
    </modules>
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <reportPlugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-project-info-reports-plugin</artifactId>
                            <version>2.7</version>
                        </plugin>

                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-checkstyle-plugin</artifactId>
                            <version>2.8</version>
                            <configuration>
                                <configLocation>sun-coding-standard.checkstyle.xml</configLocation>
                                <excludes>**/org/eclipse/cdt/core/**/*,org.eclipse.cdt.core/src/**/*,../org.eclipse.cdt.core/src/**/*,org.eclipse.cdt.core/**/*</excludes>
                                <includeTestSourceDirectory>true</includeTestSourceDirectory>
                            </configuration>
                            <reportSets>
                                <reportSet>
                                    <id>aggregate</id>
                                    <reports>
                                        <report>aggregate</report>
                                    </reports>
                                </reportSet>
                            </reportSets>
                        </plugin>

                        <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>findbugs-maven-plugin</artifactId>
                            <version>3.0.0</version>
                            <configuration>
                                <xmlOutput>true</xmlOutput>
                            </configuration>
                            <reportSets>
                                <reportSet>
                                    <id>aggregate</id>
                                    <reports>
                                        <report>aggregate</report>
                                    </reports>
                                </reportSet>
                            </reportSets>
                        </plugin>
                    </reportPlugins>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <xmlOutput>true</xmlOutput>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <configuration>
                    <aggregate>true</aggregate>
                </configuration>
            </plugin>
        </plugins>
    </reporting>
</project>

Update 1 (25.09.2014 13:03 MSK): Tried to use suppression filters by adding

<configuration>
    <configLocation>sun-coding-standard.checkstyle.xml</configLocation>
    <suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
</configuration>

with checkstyle-suppressions.xml being equal to

<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">

<suppressions>
    <suppress files="[\\/]org.eclipse.cdt.core[\\/]" checks="[a-zA-Z0-9]*"/>
    <suppress files="[\\/]org[\\/]eclipse[\\/]cdt[\\/]core[\\/]" checks="[a-zA-Z0-9]*"/>
    <suppress files="[\\/]org.eclipse.cdt.core[\\/]" checks="."/>
    <suppress files="[\\/]org[\\/]eclipse[\\/]cdt[\\/]core[\\/]" checks="."/>
</suppressions>

It didn't help.

Adding <suppressionsFileExpression>checkstyle.suppressions.files</suppressionsFileExpression> to the above <configuration> section was of no help, either.



Solution 1:[1]

This may bee a noobish question, but is there any more code in your checkstyle definition?

Usually we have something like this:

<fileset dir="src">
<include name="**/*.java"/>
<exclude name="com/myproject/util/*.java"/>
</fileset>

Where you need to say where to start scanning (source folder), what type of files to include (usually *.java) and what to exclude. In my opinion you are trying to validate too much, and not necessary things. Checkstyle is used for validation developers code, not IDE config files.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Beri