4

使用 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

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

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

4

1 回答 1

4

Looks like that's not possible...

From Sonatype blog post Configuring Plugin Goals in Maven 3:

The latest Maven release finally allows plugin users to configure collections or arrays from the command line via comma-separated strings.

Plugin authors that wish to enable CLI-based configuration of arrays/collections just need to add the expression tag to their parameter annotation.

But in the 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" };

As you can see formats doesn't have expression tag (unlike format) so it cannot be configured from the command line.

Update

I just realised that I answered wrong question :) Question I answered is "How can I generate multiple different report types from the Maven command line using 'formats' option?". But original question was "How can I generate multiple different report types from the Maven command line?"

Actually there is a simple workaround - run maven twice (second time without clean), like this:

mvn clean cobertura:cobertura -Dcobertura.report.format=xml
mvn cobertura:cobertura -Dcobertura.report.format=html
于 2014-12-03T07:58:18.627 回答