通过 Maven 命令行生成多种 Cobertura 报告格式


使用

Maven,我可以通过更改我的 POM 的报告部分来使用 Cobertura 生成多种不同类型的代码覆盖率报告,唉......

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <configuration>
        <formats>
            <format>html</format>
            <format>xml</format>
        </formats>
    </configuration>
</plugin>

或者,我可以从 Maven 命令行生成一种类型的报告,唉......

mvn clean cobertura:cobertura -Dcobertura.report.format=xml 

如何从 Maven 命令行生成多种不同的报告类型?

显然,我只能做一个。我在下面试过这个,但它不起作用!

mvn clean cobertura:cobertura -Dcobertura.report.formats=xml,html

(注意:上述属性使用"格式"与"格式"。上述内容始终创建默认的 HTML 报表,而不会看到两种指定的格式。我正在使用Maven 3.2.3和Cobertura插件版本2.0.3。

请帮忙,我的Googol Fu失败了。有谁知道这是否可能?

看起来这是不可能的...

来自Sonatype博客文章在Maven 3中配置插件目标:

最新的Maven版本终于允许插件用户配置 命令行中的集合或数组,以逗号分隔 字符串。

希望启用基于 CLI 的配置的插件作者 数组/集合只需要将表达式标签添加到它们的 参数注释。

但是在插件的代码中:

/**
 * The format of the report. (supports 'html' or 'xml'. defaults to 'html')
 * 
 * @parameter expression="${cobertura.report.format}"
 * @deprecated
 */
private String format;
/**
 * The format of the report. (can be 'html' and/or 'xml'. defaults to 'html')
 * 
 * @parameter
 */
private String[] formats = new String[] { "html" };

如您所见formats没有expression标签(与format不同(,因此无法从命令行进行配置。

更新

只是意识到我回答了错误的问题:)我回答的问题是"如何使用'格式'选项从Maven命令行生成多种不同的报告类型?但最初的问题是"如何从 Maven 命令行生成多种不同的报告类型?

实际上有一个简单的解决方法 - 运行 maven 两次(第二次没有clean(,如下所示:

mvn clean cobertura:cobertura -Dcobertura.report.format=xml
mvn cobertura:cobertura -Dcobertura.report.format=html

最新更新