Cobertura with Maven and Hudson

Cobertura and Maven: There are TWO important things to do. Then, we’ll see about integrating Cobertura and Hudson.
First, set Cobertura as one of the reports in pom.xml:

<reporting>
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>cobertura-maven-plugin</artifactId>
      <version>2.2</version> <!-- use last version available -->
    </plugin>
   </plugins>
 </reporting>

Finally, to get the actual report, you must remember to run ‘mvn site’. The reports will *not* be generated when simply running the unit tests.

For configuration, you must add a <plugin> tag in <build><plugins>; this is optional if you are only interested in Maven Site Reports. Remember: this does *not* mean that coverage analysis will be done when testing or running the code, only when running “mvn site”.

If you want the coverage reports directly under Hudson (and are not satisfied with publishing the maven site reports), things gets messy. There is a plugin for this, but I couldn’t get it to work (some people report that the current version, v0.8.4, is broken; it could also be because I’m using a Maven 2-type job under Hudson, which is not the most stable)
First, install the Cobertura-Hudson plugin.

This plugin requires XML reports to be generated by Cobertura. Looks simple enough according to the documentation.
The wiki page for the Cobertura plugin states that the configuration should be done in the <build> tag, but that didn’t work for me. In my case, I had to do it in the <reporting> tag, as follows:

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

That’s it from me. I hope you’ll have more luck than me with the Cobertura plugin. Anyway, don’t forget that you can always look for the report on the Maven-generated site. You can even create a Bookmark to it, since the page is stable (except when the build overrides it, of course).

About Eric Lefevre-Ardant

Independent technical consultant.
This entry was posted in valtech. Bookmark the permalink.

3 Responses to Cobertura with Maven and Hudson

  1. Chris Popov says:

    Eric,

    I managed to install Cobertura reports on Hudson. The thing to do I think is to use standard project style. Maven project style doesnt work. Then you can invoke cobertura goals or mvn site directly.
    One thing I had missed is that you need to call cobertura:clean before generating the report. For some reason it gets messy otherwise.

  2. Yannick says:

    Hi Eric,

    I’m looking for the DTD of Coberturas’s XML output ( Hudson Coverage plugin input) in order to parse C++ GCOV output in order to convert it in this format.

    Do you have a link to that ?

    Thanks in advance,

    Yannick.

  3. Eric Lefevre says:

    Hi Yannick,

    Sorry, I don’t have that. I suppose you might find it in Cobertura’s standard distribution, or maybe in the source files.

    Eric

Comments are closed.