SonarQube does not display detailed report per file for fully covered classes via Gradle
gradle, intellij-idea, jacoco, java, sonarqube
Solution
This is what is called 'wanted' behaviour. Sonar does not display classes with 100% coverage. In your project you have one class fully covered by tests, so nothing to show.
FYI:
Even if you have 100% covered class, you can look at this class coverage by searching in sonars search box (top-right corner).
If you see `.exec` and it is of valuable size, then you already collected coverage data.
See my FAQ
I got this code analysis widget for your project:
And finally after I added another method uncovered by tests and test coverage dropped to 80%:
I got what you need - coverage by line:
By the way, your modified build.gradle for my sonar (this `//` does not work for me):
repositories {
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'sonar-runner'
sourceCompatibility = 1.7
project.version = '1.0'
project.group = 'com.acme.sandbox'
project.description = 'just a test project'
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
// JaCoCo test coverage configuration
tasks.withType(Test) { task ->
jacoco {
append = false
}
}
// Sonar configuration
sonarRunner {
sonarProperties {
// general information about the SonarQube server
property 'sonar.host.url', 'http://localhost:9000'
property 'sonar.jdbc.url', 'jdbc:h2:tcp://localhost:9092/sonar'
property 'sonar.jdbc.validationQuery', 'select 1'
property 'sonar.jdbc.driverClassName', 'org.hibernate.dialect.H2Dialect'
property 'sonar.jdbc.password', 'sonar'
property 'sonar.jdbc.password', 'sonar'
property 'sonar.login', 'jenkins'
property 'sonar.password', 'jenkins'
// information about this project
//property 'sonar.profile', 'profilename'
property 'sonar.branch', 'DEV'
property 'sonar.language', 'java'
property 'sonar.sourceEncoding', 'UTF-8'
property 'sonar.verbose', 'true'
//property 'sonar.tests', "$projectDir\\src\\test\\java"
property 'sonar.binaries', "${buildDir}/classes/main/"
// execute JaCoCo before the SonarQube run to have report file ready
//property 'sonar.java.coveragePlugin', 'jacoco'
property 'sonar.jacoco.reportPath', "${buildDir}/jacoco/test.exec"
property 'sonar.junit.reportsPath', "${buildDir}/test-results"
}
}
Problem
I am running a Gradle build inside the IntelliJ Java IDE. The SonarQube runner Gradle plugin is used along with the JaCoCo Gradle plugin. Problem: I am getting the message `No information about coverage per test.`, (not a duplicate of this post, see below) and the coverage appears in SonarQube, but only as an overall percentage, not a detailed report per file: Am I doing something wrong? Is it a bug in SonarQube maybe (as it was with Cobertura recently)? Here is my build.gradle: ``` repositories { mavenCentral() } apply plugin: 'java' apply plugin: 'jacoco' apply plugin: 'sonar-runner' sourceCompatibility = 1.7 project.version = '1.0' project.group = 'com.acme.sandbox' project.description = 'just a test project' dependencies { testCompile group: 'junit', name: 'junit', version: '4.11' } // JaCoCo test coverage configuration tasks.withType(Test) { task -> jacoco { append = false } } // Sonar configuration sonarRunner { sonarProperties { property 'sonar.host.url', 'http://host:port' property 'sonar.jdbc.url', 'myJdbcURL' property 'sonar.jdbc.username', 'dbuser' property 'sonar.jdbc.password', 'dbpass' property 'sonar.login', 'builduser' property 'sonar.password', 'buildpass' property 'sonar.profile', 'profilename' property 'sonar.branch', 'DEV' property 'sonar.language', 'java' property 'sonar.sourceEncoding', 'UTF-8' property 'sonar.verbose', 'true' //property 'sonar.tests', "$projectDir\\src\\test\\java" //property 'sonar.binaries', "${buildDir}\\classes\\main,${buildDir}\\classes\\test" //property 'sonar.java.coveragePlugin', 'jacoco' property 'sonar.jacoco.reportPath', "${buildDir}\\jacoco\\test.exec" property 'sonar.junit.reportsPath', "${buildDir}\\test-results" } } ``` Now if you execute a `clean`, followed by `sonarRunner`, a JaCoCo test.exec file gets created and processed: ``` <snip> 18:35:27.705 DEBUG - Initializers : 18:35:27.706 INFO - Base dir: D:\path\to\JaCoCoTest 18:35:27.706 INFO - Working dir: D:\path\to\JaCoCoTest\build\sonar 18:35:27.707 INFO - Source dirs: D:\path\to\JaCoCoTest\src\main\java 18:35:27.708 INFO - Test dirs: D:\path\to\JaCoCoTest\src\test\java 18:35:27.708 INFO - Binary dirs: D:\path\to\JaCoCoTest\build\classes\main <snip> 18:35:27.931 INFO - JaCoCo IT report not found. 18:35:27.933 INFO - JaCoCo reports not found. 18:35:27.938 DEBUG - Sensors : JavaSquidSensor -> QProfileSensor -> FindbugsSensor -> CpdSensor -> PmdSensor -> SurefireSensor -> CheckstyleSensor -> InitialOpenIssuesSensor -> ProfileEventsSensor -> ProjectLinksSensor -> VersionEventsSensor -> FileHashSensor -> JaCoCoSensor <snip> 18:35:34.055 INFO - Sensor SurefireSensor... 18:35:34.056 INFO - parsing D:\path\to\JaCoCoTest\build\test-results 18:35:34.116 INFO - Sensor SurefireSensor done: 61 ms <snip> 18:35:34.936 INFO - Sensor JaCoCoSensor... 18:35:34.939 INFO - Analysing D:\path\to\JaCoCoTest\build\jacoco\test.exec 18:35:35.027 INFO - No information about coverage per test. 18:35:35.028 INFO - Sensor JaCoCoSensor done: 92 ms ``` This post suggests to set `sonar.tests`, which I've tried to no effect. The log file shows that test sources and binaries are detected to be at the correct locations. FWIW, I used the same settings with a Maven build and it worked. Can't use Maven here though. Version numbers: - SonarQube 4.3 - SonarQube Java Ecosystem 2.2.1 - Gradle 1.12 (also: 1.11) - IntelliJ IDEA Ultimate 13.1.3 - Java 1.7 Here is the full test project for download, and also the full log.