Configuring Cobertura in Maven 2

After many spurious error messages, I finally managed to make it work. Be warned that the information on the official Cobertura Maven plugin page, the informations are not exactly correct. Below, you’ll find in bold the fixes.

The “Basic Cobertura Configuration” seems fine, however, to configure the instrumentation, you need to add the following to your config file:

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.1</version> <!-- apparently, this is not necessary in the reporting part -->
        <configuration>
          <instrumentation>
            <!-- <ignore>com.example.boringcode.*</ignore> --> <!-- not sure how to make this work, or even if it is necessary at all -->
	    <excludes> <!-- the usual ant exclude pattern was missing -->
              <exclude>com/example/dullcode/**/*.class</exclude>
              <exclude>com/example/**/*Test.class</exclude>
            </excludes>
          </instrumentation>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

About Eric Lefevre-Ardant

Independent technical consultant.
This entry was posted in java, maven, test. Bookmark the permalink.

6 Responses to Configuring Cobertura in Maven 2

  1. erka says:

    I have a problem this cobertura-maven-plugin. When I create report using version 2.1 – it is wrong. Please look at
    http://erka.kpumuk.info/wp-content/uploads/2007/02/cobertura.JPG
    I have a simply maven project http://erka.kpumuk.info/wp-content/uploads/2007/02/mavencoberturatest.ZIP.
    If I use 2.0 all work fine. What do I do wrong?

    Thank.

    PS. Sorry for my English. And could you add rss for comments?

  2. Eric Lefevre says:

    Hi erka,

    I am not really the expert on using Cobertura. Though I did manage to get Cobertura to run, I don’t get a usable report as my tests are using JUnit 4 and Maven 2 does not support it. So I gave up on Cobertura eventually (until Maven 2/Surefire is updated at least).

    As for your problem, I don’t really know. The configuration seems OK, I guess. That said, in my own configuration, I didn’t specify at all the of the cobertura-maven-plugin in the section. However, I *did* specify it in the section, which is strangely missing from the pom.xml you have.

    Maybe that will help?

    Eric

    PS: apparently, to enable RSS for comments, I need to modify the theme template that I use, or at least change themes. That will be for another day.

  3. erka says:

    I try to use your configuration but nothing was changed.

    Thank for reply.

    PS. I found feed for comments.

  4. Eric Lefevre says:

    Yes, I reverted to the original theme provided by WordPress and it provides Comments RSS by default. Too bad I cannot use the theme I like, though.

  5. erka says:

    Yes, I understand. The previous theme is more beautiful that this, but it’s very simple add comments-rss and change width of comment textarea. It’s too small in my opinion. I can help you if you would like.

  6. Eric Lefevre says:

    Eventually, I think I’ll stay with an officially-approved (and tested) theme. I realized that the black theme I was using displays not well under IE. I tried fixing the display but it just took more time than I could bear…
    It would be good if themes on the official Worpress Themes site could have a level of compatibility with various web browsers.

Leave a Reply

Your email address will not be published.