如何在mavenized多模块项目中从CheckStyle分析中排除包?

问题描述 投票:0回答:1

我有一个包含多个模块的 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:\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"/>

这意味着我的

<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(2014年9月25日13:03 MSK):尝试通过添加

来使用抑制滤波器
<configuration>
    <configLocation>sun-coding-standard.checkstyle.xml</configLocation>
    <suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
</configuration>

checkstyle-suppressions.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>
部分也没有帮助。

java maven maven-3 checkstyle
1个回答
0
投票

这可能是一个新手问题,但是您的 checkstyle 定义中还有更多代码吗?

通常我们有这样的事情:

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

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

© www.soinside.com 2019 - 2024. All rights reserved.