Maven Cobertura plugin not generating coverage.xml

2019-03-09 07:11发布

I am trying to generate a coverage.xml so that I can reference it in Cobertura plugin of Hudson, but the file is not being created.

I've added the following to my POM

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

After running mvn cobertura:cobertura, the HTML site is generated as expected at **\target\site\cobertura, but coverage.xml is nowhere to be found. What am I missing/misunderstanding?

I am running Maven 3.0.3

8条回答
时光不老,我们不散
2楼-- · 2019-03-09 07:37

I had the same issue but it's resolved right now: Just add -Dcobertura.report.format=xml after your maven command. It should work

查看更多
We Are One
3楼-- · 2019-03-09 07:37

The are two ways to integrate Cobertura into Maven.

  1. Put Cobertura into the build section of the pom file, then you have to execute mvn clean cobertura:cobertura to generate the reports. If you have XML and HTML configured, then you get both reports.
  2. Put Cobertura into the reporting section of the pom file, then you have to execute mvn clean site to generate the reports. If you have XML and HTML configured, then you get both reports. Additionally you get a generated site (open target/site/index.html) with all reports integrated e.g. Coberture, Checkstyle, ...
查看更多
等我变得足够好
4楼-- · 2019-03-09 07:38

My objective was to get Cobertura to run duing mvn test with no additional command line parameters. Here's the magic XML that did the trick for me, with both the HTML and XML being generated in /target/site/cobertura.

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.7</version>
            <executions>
                <execution>
                    <id>cobertura</id>
                    <phase>test</phase>
                    <goals>
                        <goal>cobertura</goal>
                    </goals>
                    <configuration>
                        <formats>
                            <format>xml</format>
                            <format>html</format>
                        </formats>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
查看更多
何必那么认真
5楼-- · 2019-03-09 07:44

Add below lines to your application Goals:(configure section of the application in jenkins)

cobertura:cobertura -Dcobertura.report.format=xml

pom.xml changes:

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

查看更多
神经病院院长
6楼-- · 2019-03-09 07:45

Update your POM file as

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

This worked out for me: Probable reason it contanis the latest version of cobertura-maven-plugin (2.7)

查看更多
孤傲高冷的网名
7楼-- · 2019-03-09 07:47

I have the same issue using 2.6 of the plugin.

I found that when I specify both types, I only got html.

           <formats>
               <format>html</format>
               <format>xml</format>
           </formats>

But when I specify only xml, I get an xml report.

           <formats>
               <format>xml</format>
           </formats>

This is probably a bug in the plugin.

Another user suggested creating two executions. I tried that with no success (meaning I got html, but not xml).

查看更多
登录 后发表回答