Maven cobertura插件 - 一个多模块项目的报告

时间:2010-09-22 10:56:13

标签: maven-2 cobertura

我正在使用maven cobertura插件报告我的多模块项目中的代码覆盖率。

问题在于我不知道如何为项目中的所有模块生成一个报告。

到目前为止,我已经为每个模块生成了单独的报告,但是为整个项目提供一份报告会很好。

我的父pom配置:

   <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.4</version>
        <inherited>true</inherited>
        <executions>
            <execution>
                <phase>test-compile</phase>
                <goals>
                    <goal>clean</goal>
                    <goal>cobertura</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

4 个答案:

答案 0 :(得分:17)

插件已更新,因为此问题已被问及(最后一次回答)现在通过父POM中的aggregate配置属性启用汇总报告。

这将生成target/site/cobertura/index.html的聚合覆盖率报告,其中包含所有模块。

(如果有任何用途,每个模块也会生成自己的报告。)

父pom.xml

<modules>
    <module>moduleA</module>
    <module>moduleB</module>
    <module>moduleC</module>
<modules>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <check/>
                    <formats>
                        <format>html</format>
                        <format>xml</format>
                    </formats>
                    <aggregate>true</aggregate>
                </configuration>
            </plugin>
            ...
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
        </plugin>
    </plugins>
...
</build>

答案 1 :(得分:2)

据我所知,目前不支持此功能,请参阅MCOBERTURA-65。但这个问题附有补丁,也许可以尝试一下。但我的建议是使用类似Sonar的内容来聚合指标。

答案 2 :(得分:0)

我一直在使用Hudson作为持续集成工具。 Cobertura插件允许我在检查父级时查看所有子模块的代码覆盖率。

答案 3 :(得分:0)

Jenkins Cobertura插件会自动聚合报告,但如果您对覆盖文件本身感兴趣,可以通过以下步骤进行操作:

  1. here

  2. 下载Cobertura
  3. 转到项目工作区 - &gt;找到所有.ser个文件并重命名

    (i=0; find . | grep cobertura.ser$ | while read line;do echo $line; cp -i $line cobertura$i.ser;i=$(($i+1));done;)
    
  4. 使用cobertura-merge.sh生成全局.ser文件

    ~/cobertura-2.0.3/cobertura-merge.sh --datafile cobertura.ser cobertura*.ser
    
  5. 使用cobertura-report.sh生成有关全局.ser文件的报告

    ~/cobertura-2.0.3/cobertura-report.sh ./cobertura.ser --destination ./ --format xml
    
  6. 您将在当前目录中生成全局coverage.xml。 您可以将它用于任何类型的处理。

相关问题