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

Luk*_*ren 8 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>
Run Code Online (Sandbox Code Playgroud)

veg*_*4me 18

该插件已更新,因为此问题已被询问(并且最后回答),现在通过aggregate父POM中的配置属性启用聚合报告.

这将生成聚合覆盖率报告,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>
Run Code Online (Sandbox Code Playgroud)

  • 这也可以通过不编辑pom文件来完成:`mvn cobertura:cobertura -Dcobertura.aggregate = true -Dcobertura.report.format = xml`您可以根据需要更改报告格式.根据cobertura maven插件的github repo,这个功能可用[自v2.5起](https://github.com/mojohaus/cobertura-maven-plugin/blob/master/src/main/java/org/codehaus/ mojo/cobertura/CoberturaReportMojo.java#L126)(commit [64a8823](https://github.com/mojohaus/cobertura-maven-plugin/commit/64a8823866b4c8be74a44383162088d616c65185#diff-e4171be1b77f9a9b331e21a0661c1433R126)). (2认同)

Pas*_*ent 2

据我所知,目前不支持此功能,请参阅MCOBERTURA-65。不过这个问题已经附上了补丁,也许可以尝试一下。但我的建议是使用像声纳这样的东西来聚合指标。