Gradle Clover Plugin
This is an open-source extension and Atlassian does not provide technical support for it.
Gradle framework can automate the building, testing, publishing, deployment and more of software packages or other types of projects such as generated static websites or generated documentation.
Gradle Clover Plugin by Atlassian
An alpha version of plugin written by Atlassian developers, it offers basic functionality:
bitbucket.org/atlassian/gradle-clover-plugin
Gradle Clover Plugin by Benjamin Muschko
A quite functional Clover plugin written by Benjamin Muschko:
https://github.com/bmuschko/gradle-clover-plugin
Known issues:
- https://github.com/bmuschko/gradle-clover-plugin/issues
- plug-in requires presence of "main" source directory (e.g. src/main/groovy)
- a default test inclusion pattern is "**/*Test.java" and "**/*Test.groovy", so in case you have other test naming convention (for instance, Spock framework has "*Spec.groovy") you have to declare clover.testIncludes property in build.gradle
Integrating Clover manually
In case you would like to integrate Clover manually in your build.gradle script, then you need to handle at least three tasks:
- code instrumentation - pass sources to CloverInstr (Java only), next pass instrumented sources to the 'compile' task
- test execution - add clover.jar to the test classpath
- report generation - call HtmlReporter or XMLReporter
Example:
apply plugin: 'java'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
testCompile 'junit:junit:4.12'
}
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.atlassian.clover:clover:4.1.1'
}
}
sourceSets {
clover {
java {
srcDir "$buildDir/sources-instr"
}
}
}
dependencies {
cloverCompile 'com.atlassian.clover:clover:4.1.1'
}
configurations {
cloverRuntime
cloverRuntime.extendsFrom cloverCompile
}
task cloverInstr() {
inputs.files sourceSets.main.allJava
outputs.dir "$buildDir/sources-instr"
doFirst {
def argsList = ["--initstring", "${buildDir}/clover/clover.db",
"-d", "${buildDir}/sources-instr"]
argsList.addAll(inputs.files.files.collect({ file ->
file.absolutePath
}))
String[] args = argsList.toArray()
com.atlassian.clover.CloverInstr.mainImpl(args)
}
}
cloverClasses.dependsOn cloverInstr
test {
def cloverClasspath = configurations.testRuntime + configurations.cloverRuntime + sourceSets.test.output + sourceSets.clover.output
classpath = cloverClasspath
}
task cloverReport {
inputs.dir "${buildDir}/clover"
outputs.dir "${reportsDir}/clover"
onlyIf {
file("${buildDir}/clover/clover.db").exists()
}
doFirst {
def argsList = ["--initstring", "${buildDir}/clover/clover.db",
"-o", "${reportsDir}/clover"]
String[] args = argsList.toArray()
com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
}
}
References
- CLOV-1009Getting issue details... STATUS - feature request for Clover
- BAM-9368Getting issue details... STATUS - Gradle plugin for Bamboo - a Gradle Task is available in the free bamboo-artifactory-plugin.