Reputation: 1295
I am using sonarqube + jacoco for codecoverage, i have junit test case for my java code in below dir structure.
src/main/java/code/abc.java
src/main/test/code/Testabc.java
I want a code coverage on sonarqube dashboard and i am using gradle for the same.
apply plugin: "java"
apply plugin: "org.sonarqube"
apply plugin: "jacoco"
jacoco {
toolVersion = "0.7.9"
reportsDir = file("${project.buildDir}/jacoco/customJacocoReportDir")
}
sonarqube {
properties {
property "sonar.sources", "."
property "sonar.projectName", "javacode"
property "sonar.projectKey", "javacode"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.java.binaries", "/data/tmp/env/"
property "sonar.jacoco.reportPath", "${project.buildDir}/jacoco/test.exec"
}
}
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7"
}
}
I am running gradle sonarqube
I dont know where i am doing wrong? if any one can help to get the coverage of test case written from java code.
Upvotes: 1
Views: 1002
Reputation: 14515
Here's the minimal config that is working with
Gradle snippet:
apply plugin: "org.sonarqube"
apply plugin: "jacoco"
// jacoco task config not needed since I'm using the defaults (latest version, default dir)
// jacoco {
// toolVersion = "0.7.9"
// reportsDir = file("${project.buildDir}/jacoco/customJacocoReportDir")
// }
sonarqube {
properties {
property "sonar.sources", "."
property "sonar.projectName", "javacode"
property "sonar.projectKey", "javacode"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.java.binaries", "/data/tmp/env/"
// no need to define sonar.jacoco.reportPaths or sonar.coverage.jacoco.xmlReportPaths as sonarqube
// finds the xml report in the default location (build/reports/jacoco/test/jacocoTestReport.xml)
// property "sonar.jacoco.reportPath", "${project.buildDir}/jacoco/test.exec"
}
}
jacocoTestReport {
reports {
xml.enabled true // to be sure xml report is created (sonarqube knows jacoco's default report location)
}
}
Upvotes: 0
Reputation: 28136
It seems to me, that Jacoco test reports are generated in one directory, but SoanrQube is configured to look into another one. Here is the directory you save reports:
reportsDir = file("${project.buildDir}/jacoco/customJacocoReportDir")
and here is Sonar configuration to look up Jacoco results:
property "sonar.jacoco.reportPath", "${project.buildDir}/jacoco/test.exec"
There is customJacocoReportDir
directory missed
Upvotes: 0