-
Notifications
You must be signed in to change notification settings - Fork 50
Home
The Cobertura plugin adds cobertura code coverage targets to a project
To use the Cobertura plugin, include in your build script:
apply plugin: org.gradle.api.plugins.CoberturaPlugin
In addition, add github as a repository for your buildscript:
buildscript {
// using a variable to make wiki look cleaner
def githubBase = 'https://github.com/valkolovos/gradle_cobertura/raw/master/ivy'
repositories {
/* keep any existing buildscript repositories you might have */
/* here's the github repository */
add(new org.apache.ivy.plugins.resolver.URLResolver()) {
name = 'cobertura'
addArtifactPattern "${githubBase}/[organization]/[module]/[revision]/[module].[ext]"
addIvyPattern "${githubBase}/[organization]/[module]/[revision]/ivy.xml"
}
mavenCentral() // you'll need this if you don't already have it
}
dependencies {
classpath 'gradle_cobertura:gradle_cobertura:1.0-rc2' // here's the ivy resolution for the cobertura plugin
}
}
The code will only be instrumented if a GenerateCoverageReportTask is in the task graph.
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
You can customize the behavior of the Cobertura plugin by using a closure to configure the convention properties
cobertura {
}
- 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
- default value is project.buildDir.path
- coverageReportDir (type: String) -Path to report directory for coverage report.
- default value is project.reportsDir.path
/cobertura
- default value is project.reportsDir.path
- coverageFormat (type: String) – Format of cobertura report.
- default value is
html
- default value is
- 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
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\\..*' ]
}