Maven 3.0.5中的汇总findbugs报告

Maven 3.0.5中的汇总findbugs报告,maven,maven-3,findbugs,Maven,Maven 3,Findbugs,我正在使用多模块Maven项目(超过10个模块)。我试图在一个html页面中创建所有模块的findbugs报告。有办法吗 为了为每个模块创建单独的报告,我使用下面的 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <version>3.0.0</version

我正在使用多模块Maven项目(超过10个模块)。我试图在一个html页面中创建所有模块的findbugs报告。有办法吗

为了为每个模块创建单独的报告,我使用下面的

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>findbugs-maven-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
        <!--
            Enables analysis which takes more memory but finds more bugs.
            If you run out of memory, changes the value of the effort element
            to 'Low'.
        -->
        <effort>Max</effort>
        <!-- Build doesn't fail if problems are found -->
        <failOnError>false</failOnError>
        <!-- Reports all bugs (other values are medium and max) -->
        <threshold>Low</threshold>
        <!-- Produces XML report -->
        <xmlOutput>false</xmlOutput>
        <skip>${skipFindbugs}</skip>
        <!-- Configures the directory in which the XML report is created -->
        <findbugsXmlOutputDirectory>${project.build.directory}/findbugs</findbugsXmlOutputDirectory>
    </configuration>
    <executions>
        <!--
            Ensures that FindBugs inspects source code when project is compiled.
        -->
        <execution>

            <phase>compile</phase>
            <goals>
                <goal>findbugs</goal>
            </goals>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>xml-maven-plugin</artifactId>
    <version>1.0</version>
    <configuration>
        <transformationSets>
            <transformationSet>
                <!-- Configures the source directory of XML files. -->
                <dir>${project.build.directory}/findbugs</dir>
                <!-- Configures the directory in which the FindBugs report is written.-->
                <outputDir>${project.build.directory}/findbugs</outputDir>
                <!-- Selects the used stylesheet. -->
                <!-- <stylesheet>fancy-hist.xsl</stylesheet> -->
                <stylesheet>${project.parent.basedir}/default.xsl</stylesheet>
                <!--<stylesheet>plain.xsl</stylesheet>-->
                <!--<stylesheet>fancy.xsl</stylesheet>-->
                <!--<stylesheet>summary.xsl</stylesheet>-->
                <fileMappers>
                    <!-- Configures the file extension of the output files. -->
                    <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                        <targetExtension>.html</targetExtension>
                    </fileMapper>
                </fileMappers>
            </transformationSet>
        </transformationSets>
    </configuration>
    <executions>
        <!-- Ensures that the XSLT transformation is run when the project is compiled. -->
        <execution>

            <phase>compile</phase>
            <goals>
                <goal>transform</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>findbugs</artifactId>
            <version>3.0.0</version>
        </dependency>
    </dependencies>
</plugin>

org.codehaus.mojo
findbugs maven插件
3.0.0
马克斯
假的
低
假的
${skipFindbugs}
${project.build.directory}/findbugs
编译
芬德布格斯
org.codehaus.mojo
xml maven插件
1
${project.build.directory}/findbugs
${project.build.directory}/findbugs
${project.parent.basedir}/default.xsl
.html
编译
使改变
com.google.code.findbugs
芬德布格斯
3.0.0
根据插件的定义(问题1),这是不可能的

然而,以下是我用来实现它的方法:

  • 向现有多模块项目中添加其他模块。此附加模块仅用于报告
  • 配置以将其他模块的源代码动态添加到报告模块。注意:如果需要,您可以对资源执行相同的操作
  • 仅在报告模块上配置Findbugs插件
  • 添加其他模块作为报告模块的依赖项,以便Maven reactor build只在最后构建它
  • 如果需要:如果不希望报告模块成为默认生成的一部分,请在聚合器/父模块中创建一个概要文件,重新定义
    模块
    元素并将报告模块添加到其中。因此,只有在激活概要文件时(即通过命令行,按需),才会添加报告模块并创建聚合报告
例如,在聚合器/父模块中,您可以定义如下:

<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>com.sample</groupId>
    <artifactId>findbugs-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>findbugs-module1</module>
        <module>findbugs-module2</module>
    </modules>

    <profiles>
        <profile>
            <id>findbugs-reporting</id>
            <modules>
                <module>findbugs-module1</module>
                <module>findbugs-module2</module>
                <module>findbugs-reporting</module>
            </modules>
        </profile>
    </profiles>
</project>
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.9.1</version>
    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>..\findbugs-module1\src\main\java</source>
                    <source>..\findbugs-module2\src\main\java</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>
因此,您将构建整个项目并另外激活报告模块,该模块将动态地包括来自其他模块(如配置)的源,并生成聚合报告


根据您的需要,您可以避免配置文件步骤(如果您想将其作为默认生成的一部分)或在默认情况下激活配置文件(以便您可以跳过报告生成并通过
-p!findbugs reporting
将其停用),或使用已配置的
skipFindbugs
属性(在这种情况下,不使用配置文件).

将依赖项目的源文件夹添加到聚合器中感觉非常难看:(。但至少这是可行的。要将报表作为
mvn站点的一部分创建,您只需将插件放在
-部分即可,我不需要任何其他配置。
<dependencies>
    <dependency>
        <groupId>com.sample</groupId>
        <artifactId>findbugs-module1</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.sample</groupId>
        <artifactId>findbugs-module2</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>
mvn clean install -Pfindbugs-reporting