4

I'm using maven-cobertura-plugin in order to calculate code coverage in my project. As I understand, this plugin starts a new/forked build cycle in order to compile and test the code base. When it's done the plugin calculates code coverage. As I understand, this is the only approach the plugin can use, and it's fine for me.

The problem is that before cobertura plugin my code base is compiled and tested already. Thus, I'm experiencing duplicated compilation and testing. Is it possible to avoid compilation and testing before cobertura? Or maybe there is some other workaround?

yegor256
  • 102,010
  • 123
  • 446
  • 597

3 Answers3

1

Is it possible to avoid compilation and testing before cobertura? Or maybe there is some other workaround?

There are several issues about this (see MCOBERTURA-83, MCOBERTURA-76) but AFAIK, there is no perfect workaround (due to the way the life cycle is constructed - things might be improved in Maven 3).

The only one I'm aware of (works with CI servers) would be to run:

mvn clean install -Dmaven.test.skip=true

and then

mvn cobertura:check

Instead of binding cobertura:check on the build lifecycle.

Note that compiling twice shouldn't be an issue as all classes should be up to date.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • this is really helpful thanks a lot.. but in my case cobertura printing some unwanted exception logs, is there any way to stop them? – Spark-Beginner Feb 04 '14 at 08:01
  • Be careful if this is in a CI environment. What I found is that when tests fail during the cobertura execution, they don't cause the build to fail. For this reason, my CI server does `mvn clean install cobertura:cobertura`, effectively running all the tests twice. Unfortunately, looking at the activity in the plugin's JIRA, I have little hope that this will ever be resolved. :( – Jeff Fairley Apr 07 '15 at 17:45
0

The only way I was able to work around that was to instrument the byte code as part of my build (by binding the cobertura:instrument goal to the verify phase and also bind the default-test execution from maven-surefire-plugin to the verify phase so it doesn't get executed as part of the test phase on every cobertura goal execution.

Roberto Andrade
  • 1,793
  • 1
  • 21
  • 27
0

As far as I know, cobertura needs to do bytecode weaving on your code to be able to work.

Kurt Du Bois
  • 7,550
  • 4
  • 25
  • 33