如何在专业化的多模块项目中从CheckStyle分析中排除包



我有一个Maven项目,它有几个模块,包括org.eclipse.cdt.core。出于某种原因,客户也想构建org.eclipse.cdt.core

我想生成一个聚合的Checkstyle报告,其中排除了一些文件,包括所有org.eclipse.cdt.core.*(包括子包)类。

为此,我将excludes标签指定为

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

然后我运行mvn clean checkstyle-aggregate site,打开文件target/checkstyle-result.xml,发现其中有以下行:

<file name="C:devideorg.eclipse.cdt.coresrcorgeclipsecdtcoreAbstractExecutableExtensionBase.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"/>

这意味着我的<excludes>标签不起作用。

然后,我把线

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

转换为要从Checkstyle中排除的所有模块的pom.xml文件,但这没有帮助。

如何在没有某些模块的结果的情况下生成CheckStyle报告(XML或HTML)(除了使用180 MB的大target/checkstyle-result.xml并从中删除所有"错误"的文件类型)?

<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>

更新1(25.09.2014 13:03 MSK):尝试通过添加使用抑制滤波器

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

检查样式抑制.xml等于

<?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>

这没用。

<suppressionsFileExpression>checkstyle.suppressions.files</suppressionsFileExpression>添加到上述<configuration>部分也没有帮助。

这可能是一个很难回答的问题,但您的检查样式定义中还有更多的代码吗?

通常我们有这样的东西:

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

您需要说明从哪里开始扫描(源文件夹),包括什么类型的文件(通常是*.java)以及排除什么。在我看来,你试图验证太多,而不是必要的东西。Checkstyle用于验证开发人员的代码,而不是IDE配置文件。

最新更新