【问题标题】:Generating multiple Cobertura report formats via Maven command line通过 Maven 命令行生成多种 Cobertura 报告格式
【发布时间】:2014-12-03 00:20:30
【问题描述】:

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

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

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

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

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

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

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

(注意:上面的属性使用“格式”与“格式”。上面的 always 创建默认的 HTML 报告而没有看到两种指定的格式。我使用的是 Maven 3.2.3 和 Cobertura插件版本 2.0.3。)

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

【问题讨论】:

    标签: java maven sonarqube cobertura maven-cobertura-plugin


    【解决方案1】:

    看来这是不可能的……

    来自 Sonatype 博文Configuring Plugin Goals in Maven 3

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

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

    但是在code of the plugin:

    /**
     * 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
    

    【讨论】:

    • 谢谢,回答了。奇怪的是,格式被标记为“已弃用”,但格式未激活。
    • 这是一个很好的解决方法,但对于像 Jenkins 这样的构建系统执行两次分析并不是很有效。无论如何,第一个答案抓住了我的问题的要点。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2014-12-01
    • 2011-03-02
    • 2014-02-06
    • 2013-04-27
    • 2010-10-10
    • 2016-12-04
    • 1970-01-01
    • 2011-07-10
    相关资源
    最近更新 更多