Maven Cobertura plugin not generating coverage.xml
Asked Answered
O

8

41

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

Overfeed answered 22/2, 2012 at 16:19 Comment(0)
O
7

I'm still quite a novice with the connections between Maven Plugins and Hudson and it's plugins - so this isn't an intelligent answer by any means, but help on Google is very few and far between for this issue - so hopefully it helps someone in the future.

After spending a few more hours of tinkering with settings, I've found that the coverage.xml simply doesn't seem to be built locally.

This is the combination that got it working:

  1. I had changed my version to 2.2 in my POM (I was getting resource not found errors from Apache with 2.5.1)
  2. Added cobertura:cobertura in my Hudson goal
  3. Set the Cobertura coverage pattern to the recommended **/target/site/cobertura/coverage.xml
Overfeed answered 22/2, 2012 at 21:1 Comment(0)
F
30

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>

Farhi answered 5/6, 2014 at 9:10 Comment(2)
Note that even though the pom configuration specifies both html and xml, the command line argument overrides that, instructing the plugin to generate only xml.Keynote
Thanks for the -D argumentFurther
P
27

I put the plugin in the build section and it works:

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

The reporting section and its differences to the plugin section are described here. I don't know if this is a maven [3.0.4] or cobertura-plugin issue.

Pikeman answered 22/2, 2012 at 21:6 Comment(0)
O
7

I'm still quite a novice with the connections between Maven Plugins and Hudson and it's plugins - so this isn't an intelligent answer by any means, but help on Google is very few and far between for this issue - so hopefully it helps someone in the future.

After spending a few more hours of tinkering with settings, I've found that the coverage.xml simply doesn't seem to be built locally.

This is the combination that got it working:

  1. I had changed my version to 2.2 in my POM (I was getting resource not found errors from Apache with 2.5.1)
  2. Added cobertura:cobertura in my Hudson goal
  3. Set the Cobertura coverage pattern to the recommended **/target/site/cobertura/coverage.xml
Overfeed answered 22/2, 2012 at 21:1 Comment(0)
A
3

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>
Adam answered 12/2, 2017 at 2:39 Comment(0)
I
1

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

Igorot answered 1/12, 2016 at 19:3 Comment(0)
K
0

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).

Keynote answered 7/2, 2015 at 6:36 Comment(0)
S
0

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)

Signature answered 15/4, 2016 at 11:17 Comment(0)
A
0

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, ...
Aromatize answered 16/11, 2016 at 9:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.