Hi Folks,
I have the beginnings of jacoco code coverage in my gradle (1.6) multi-module project. I’m using the jacoco plugin syntax and from a local build, I’m getting what appear to be correct outputs of code coverage (comparable to cobertura reports). Where things start to get a little strange is when I run my build against sonar (3.2). What I’m seeing is drastically lower code coverage levels. For a module on my local build, I have around 79% line coverage. The same module reported in sonar is around 40%.
My local command is:
gradle clean build jacocoTestReport
And my command to run sonar:
gradle classes sonarAnalyze check --info
Below shows how I’m configuring things. Hopefully someone has some insight on what’s going on here. Thanks!
In my parent gradle file, I declare sonar. What’s interesting is the value for the sonar.jacoco.reportPath doesn’t seem to be used, I can change the value to anything and it still runs a report to sonar.
sonar {
server {
url = "http://sonar.acme.net:8020"
}
database {
url = "jdbc:mysql://sonar.acme.net:3306/sonar"
driverClassName = "com.mysql.jdbc.Driver"
}
project {
dynamicAnalysis = "reuseReports"
withProjectProperties { props ->
props["sonar.core.codeCoveragePlugin"] = "jacoco"
props["sonar.jacoco.reportPath"] = "$reportsDir/jacoco/jacocoTest.exec"
}
withGlobalProperties { props ->
props["sonar.projectKey"] = "content-dam"
props["sonar.projectName"] = "content-dam"
}
}
}
Then within the sub-project gradle file:
jacoco {
toolVersion = "0.6.2.201302030002"
}
test{
jvmArgs '-XX:-UseSplitVerifier'
jacoco {
append = false
destPath = file("$buildDir/jacoco/jacocoTest.exec")
classDumpPath = file("$buildDir/jacoco/classpathdumps")
}
}
jacocoTestReport {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
reports {
xml.enabled true
csv.enabled false
html.destination "${buildDir}/jacocoHtml"
}
classDirectories = fileTree(dir: 'build/classes/main', include: 'com/**')
sourceDirectories = fileTree(dir: 'scr/main/java', include: 'com/**')
}