Generating multiple Cobertura report formats via Maven command line

4.1k Views Asked by At

With Maven I can generate multiple different types of code coverage reports with Cobertura by changing the reporting section of my POM, ala ...

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

Alternately, I can generate a single type of report from the Maven command line, ala ...

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

How can I generate multiple different report types from the Maven command line?

Apparently, I can only do one. ... I've tried this below, and it does not work!

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

(NOTE: The above property uses "formats" versus "format". The above always creates the default HTML report without seeing the two specified formats. I'm using Maven 3.2.3 and Cobertura plugin version 2.0.3.)

Please help, my Googol Fu is failing. ... Anyone know if this is possible or not?

1

There are 1 best solutions below

2
On BEST ANSWER

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