NOTE: This plugin was integrated into Gradle in version 1.6 and this repo will no longer be maintained. See their user guide for more information on the new plugin.
A plugin for adding Jacoco support to the Gradle build tool.
API Documentation
Add the following lines to your build to use the gradle-jacoco plugin.
buildscript {
repositories { mavenCentral() }
dependencies { classpath 'org.ajoberstar:gradle-jacoco:0.2.0' }
}
apply plugin: 'jacoco'
When the plugin is applied, it will add an extension to the project providing options for configuring the version of Jacoco to use, as well as applying the Jacoco agent to tasks.
By default, all Test
tasks will have Jacoco support turned on.
If you use the sonar
or sonar-runner
plugins, the jacoco
plugin will automatically
set the unit test and integration test report paths for the project. It
will assume that unit test data should come from the test
task and that
integration test data, if any, will come from an intTest
or integTest
task.
Any tasks that have Jacoco applied will have their own extension that allows configuration of specific Jacoco options.
You can use the jacoco
extension
on the project to do high-level configuration and apply Jacoco to additional tasks.
jacoco {
// change the version of Jacoco in use
toolVersion = '0.6.2.201302030002'
// apply to a specific task that implements JavaForkOptions
applyTo(someJavaExecTask)
// apply to any collection of tasks. any that implement
// JavaForkOptions will have Jacoco applied
applyTo(tasks.withType(JavaExec))
}
Any tasks that has Jacoco applied to it will have a jacoco
extension
that provides access to all of the properties passed into the agent. The extension can
also be used to disable Jacoco on the specific task.
test {
jacoco {
// would have been enabled by default
enabled = true
// change path of execution data
destPath = 'build/somewhere/else.exec'
}
}
If you need to have a single execution file (which is not required for report generation) you can use the JacocoMerge task.
import org.ajoberstar.gradle.jacoco.tasks.*
task mergedData(type: JacocoMerge) {
// can pass in any task set up for Jacoco
executionData test, integTest
}
If you want an HTML report of your coverage, you can use the JacocoReport task. Report tasks will be created
automatically for test
, intTest
, and integTest
tasks, if any.
import org.ajoberstar.gradle.jacoco.tasks.*
task jacocoReport(type: JacocoReport) {
// can include one or more execution files
executionData test, integTest
// specify one or more source sets that you want to report on the coverage of
sourceSets project.sourceSets.main
// can also specify additional class and source dirs
// additionalClassDirs moreStuff
// additionalSourceDirs moreSourceStuff
}
v0.3.0
- Fixed
JacocoReport
tasks to only run if all of their execution data input was created. - Fixed automatic Sonar configuration (See #8)
- Added configuration option to specify the unit and integration task names used for configuration of Sonar and report tasks. (See #9)
v0.2.0
- Improved the API of the
JacocoReport
andJacocoMerge
tasks. - Added default
JacocoReport
tasks for anytest
,intTest
, andintegTest
tasks to determine coverage of themain
source set. - Support for the
sonar-runner
plugin coming in Gradle 1.5. - Licensed under Apache Software License.
v0.1.0
Initial release. Very rough support in place.