Here are the configuration details for common build tools. Please feel free to update this with corrections or additions.
You can either, enable "cobertura" analysis in your 'pom.xml' files or just tell Jenkins to run "cobertura" goal.
If you don't want to change your pom files, just add the goal 'cobertura:cobertura' to your Maven project in Jenkins.
If you are using a single module configuration, add the following into your pom.xml. This will cause cobertura to be called each time you run "mvn package".
You can reduce the load of your developer machine by using maven profiles to execute the plugin only if you are running within Jenkins. The configuration below shows how to enable the plugin based on the information if maven was started by Jenkins.
If you are using a common parent for all Maven2 modules you can move the plugin configuration to the pluginManagement section of the common parent...
And add the plugin group and artifact to the children
It is highly recommend to reduce the workload of the developers machines by disabling the cobertura plugin and only using it from within Jenkins. The following excerpt from the parent shows how to do so:
Now that your parent is only using the plugin management section if it is running from within Jenkins, you need the childern poms adapted as well:
You must first tell Ant about the Cobertura Ant tasks using a taskdef statement. The best place to do this is near the top of your build.xml script, before any target statements.
You'll need to instrument the classes that JUnit will be testing (not the test classes themselves) as such:
Here's an example call to the JUnit ant task that has been modified to work with Cobertura.
Finally, you need a task to generate the xml report, where 'destdir' is where you want the report (coverage.xml) generated.
Your cobertura.ser is generated to your module root.
srcdir is where your *.java files are located. If you use multiple modules in one build process you need to include the module name, if you use the simple srcdir parameter. It is not required to include module name if you use fileset.
Running Cobertura in gradle, copied from Piotr Gabryanczyk's post at http://piotrga.wordpress.com/2010/04/17/gradle-cobertura-integration-revisited/ and tweaked to work for gradle 1.5:
Create cobertura.gradle in the root of your project:
Apply Cobertura.gradle in your build.gradle
Either (if single project build)
Or (if multi project build)
Note that the conditional coverage is the highest coverage from all the cobertura reports aggregated in each build. Thus if you have two reports and one covers only 50% of a conditional and the other covers a different 25%, conditional coverage will be reported as 50% and not the 75% that you could argue it should be!
Skip to end of metadata Go to start of metadata