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"
}
sourceSets.main.java
andsourceSets.test.java
doesn't seem right. Also thedoFirst
doesn't seem right. Things likeclassDumpFile
shouldn't have to be configured manually (unless you aren't happy with the defaults). Perhaps start from one of the JaCoCo sample builds in the full Gradle distribution. – Peter NiederwiesersourceSets.main.java
andsourceSets.test.java
, and removedclassDumpFile
. However I am not clear what is wrong withdoFirst{}
. Any clues? – MFIhsanclassDirectories
withdoFirst
. I wasn't talking aboutclassDumpFile
in particular. Just saying that the more defaults are changed, the higher the chance of going wrong somewhere. Again, check the samples in the full Gradle distribution. – Peter Niederwieser