Skip to content
This repository

Cobertura Plugin

The Cobertura plugin adds cobertura code coverage targets to a project. See announcements and changes here.

Usage

To use, add the following to your build.gradle file:

Gradle 1.0-milestone-7 and later:

buildscript {
    apply from: 'https://github.com/valkolovos/gradle_cobertura/raw/master/repo/gradle_cobertura/gradle_cobertura/1.0/coberturainit.gradle'
}

Gradle 1.0-milestone-6 and earlier:
buildscript {
    apply from: 'https://github.com/valkolovos/gradle_cobertura/raw/master/repo/gradle_cobertura/gradle_cobertura/1.0-rc4/coberturainit.gradle'
}

The code will only be instrumented if a GenerateCoverageReportTask is in the task graph.

Tasks

The Cobertura plugin adds the following tasks to a project:

  • cobertura – Executes tests and generates a cobertura code coverage report in the directory specified by the convention’s reportDir property
    • depends on: cleanTest, test
    • type: com.orbitz.gradle.cobertura.tasks.GenerateCoverageReportTask

Customizing

You can customize the behavior of the Cobertura plugin by using a closure to configure the convention properties

cobertura {
}

Convention Properties

  • coverageDirs (type: List) – Directories under the base directory containing classes to be instrumented.
    • default value is [ project.sourceSets.main.classesDir.path ]
  • coverageDatafile (type: File) – Path to data file to use for Cobertura.
    • default value is project.buildDir.path/cobertura/cobertura.ser
  • coverageReportDir (type: String) -Path to report directory for coverage report.
    • default value is project.reportsDir.path/cobertura
  • coverageFormat (type: String) – Format of cobertura report.
    • default value is html
  • coverageSourceDirs (type: Set) – Directories of source files to use.
    • default value is project.sourceSets.main.java.srcDirs
  • coverageIncludes (type: List) – List of regular expressions to specify which class files to include in coverage report
    • default value is an empty set
  • coverageExcludes (type: List) – List of regular expressions to specify which class files to exclude from coverage report
    • default value is an empty set

These properties are provided by a org.gradle.api.plugins.CoberturaConvention object

GenerateCoverageReportTask

You can add custom instances of this task to do generate additional coverage reports. For example, you might want to have an XML format of the coverage report generated. To do that, you would add another task of type GenerateCoverageReportTask like this:

task generateXmlCoverage(type: com.orbitz.gradle.cobertura.tasks.GenerateCoverageReportTask, dependsOn: 'cobertura') {
    format = 'xml'
    coverageExcludes = [ '.*org\\.foo\\..*' ]
}
Something went wrong with that request. Please try again.