Got it working.

So, just in case others wish to use Cobertura with gradle,
and want to go about it using the ANT style interface, this is everything I
needed to do to set it up

file: build.gradle
-------------------------

// setup a property which points to the cobertura root path
if (getProject().properties['codeCoverageProvider']==null)
 getProject().setProperty('codeCoverageProvider',
'/mnt/data/bin/cobertura-1.9.4.1')

// a custom configuration
configurations{
instrumentation
}


dependencies {
instrumentation files("${project.buildDir}/cobertura-instrumentation")
testRuntime files("${codeCoverageProvider}/cobertura.jar")

      // the rest of your dependencies here
}


sourceSets {
    // place your instrumented classes at the FRONT of the list of TEST
runtime
    //  dependencies (including the original compiled project classes ) so
that they get preference at test time
    runtimeClasspath = configurations.instrumentation + runtimeClasspath
}


test{
     // I prefer to ignore test failures, especially as I have a
multi-project build
ignoreFailures = true
    // we need this because the 'datafile' argument of the cobertura ant
tasks doesn't take complete effect
systemProperties['net.sourceforge.cobertura.datafile'] =
"${project.buildDir}/cobertura.ser"
}


test.doFirst { // coverage

println "Setting up cobertura code coverage instrumentation"

ant.taskdef(resource:'tasks.properties') {
classpath {
 pathelement(location:"${codeCoverageProvider}/cobertura.jar")
fileset(dir:"${codeCoverageProvider}/lib", includes:'*.jar')
 }
}

println "instrumentation to: ${project.buildDir}/cobertura-instrumentation"

ant.'cobertura-instrument'(toDir:
"${project.buildDir}/cobertura-instrumentation", datafile:
"${project.buildDir}/cobertura.ser"){
 fileset(dir: "${sourceSets.main.classesDir}"){
include(name: "**/*.class")
 }
}
}


test.doLast{
println "Writing cobertura report"

ant.'cobertura-report'(destdir: "${project.buildDir}/cobertura-report",
datafile: "${project.buildDir}/cobertura.ser"){
 sourceSets.main.java.srcDirs.each { dir ->
if (dir.isDirectory()){
fileset(dir: "${dir}"){
 include(name: "**/*.java")
}
}
 }
}
}

--------------------- end of file ----------------------------------

Reply via email to