I have a Gradle project configured with jacoco plugin to report the test code coverage. My unit tests are written in Spock framework.
Though the Jacoco plugin generates the HTML report, it reports the code coverage as 0% on all classes.
I googled a lot and couldn't find what I'm missing. Has anyone got the Spock code coverage working with Gradle + Jacoco?
apply plugin: "jacoco"
apply plugin: "groovy"
sourceSets {
main {
java { srcDirs = ['src/main/java'] }
groovy {srcDirs = ['src/main/groovy'] }
resources { srcDir 'src/main/resources' }
}
test {
java { srcDirs = ['src/test/java'] }
groovy { srcDirs = ['src/test/groovy'] }
resources { srcDir 'src/test/resources' }
}
}
test {
jvmArgs '-Xms64m', '-Xmx2G', '-XX:MaxPermSize=128m'
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.destination "${buildDir}/jacocoHtml"
}
}
dependencies {
testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
testCompile "org.spockframework:spock-spring:0.7-groovy-2.0"
}
Suggestion from @PeterNiederwieser worked perfectly. Here is the final result:
apply plugin: "groovy"
apply plugin: "jacoco"
repositories { mavenCentral() }
dependencies {
compile "org.codehaus.groovy:groovy-all:2.2.2"
testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.destination "${buildDir}/jacocoHtml"
}
}