Sonar doesn’t display coverage information after analysis of my Kotlin project with the new SonarKotlin (official) plugin (I was working with another non-official Kotlin plugin).
With the new SonarKotlin, it is not yet possible to import JaCoCo reports. We are working on it and this time the idea is to support the XML format instead of the binary one. See https://jira.sonarsource.com/browse/MMF-1362 for more details.
I already tried to send Kotlin Code Coverage (https://jira.sonarsource.com/browse/MMF-1362), but it didnt show up on Sonarqube, it shows 0% coverage. I already set the xml.enabled to true and make sure the xml file is there.
This is how it looks on my project:
property “sonar.coverage.jacoco.xmlReportPaths”, “build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml”
There is no problem with Java coverage. I use Kotlin + Java in my project.
Did I do anything wrong with the script? Any help is appreciated.
I use sonarqube Version 7.1 (build 11001) on docker
Excuse my ignorance but is this something that needs to be rolled out to sonarcloud.io?
I can’t tell what happens to MMF-1362 in terms of higher level processes.
On my side I’m using the 2.6.2 of the org.sonarqube Gradle plugin to try to send the XML report to sonarcloud.io and my gradle.properties has: systemProp.sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/test/jacocoTestReport.xml
I am using that exactly same configuration, and my project is working showing coverage. But I am running on some issues, because it is not grabbing the coverage of all my classes. There some classes showing the right coverage, but some others are showing 0%. I think there are some issues in this plugin.
Also Please note that in the documentation says that you need to have the JaCoCo plugin on your server instance. After I install this plugin, I started getting the coverage. Before, with the sonar detekt plugin, I didn’t need to have the jacoco one installed.
Thank you Manuel! That’s right, I need to install jacoco plugin on the server. My coverage is now showing. And as far as I checked, I have no issue yet regarding the 0% coverage for some files. However, I’ll keep checking and will pop out here if I find something.
I am using the SonarJaCoCo version 1.0.1 and SonarKotlin 1.2 in my own sonar installation, and I am getting errors with some classes, where the coverage can not be retrieved. So for that specific class I am getting 0% coverage, but with others I can see the right one.
This is an example of one error I am getting:
Cannot import coverage information for file 'src/main/java/com/SomeClass.kt', coverage data is invalid. Error: {}
java.lang.IllegalStateException: Line 76 is out of range in the file src/main/java/com/SomeClass.kt (lines: 75)
at org.sonar.api.internal.google.common.base.Preconditions.checkState(Preconditions.java:197)
at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.validateLine(DefaultCoverage.java:93)
...
It seems to be the same error described in https://jira.sonarsource.com/browse/JACOCO-3. How should I proceed? Do I need to create a ticket? I am new here, so it would be great you could help me.
This message “Cannot import coverage information for file” is exactly the fix we did this week to prevent the full code scan to stop because the JaCoCo XML file is containing invalid data.
This is now expected to have it on a couple of files and have 0% of coverage for these files in SonarQube.
If after execution of gradle test jacocoTestReport you’ll open build/reports/jacoco/test/html/index.html, then you can notice that content of source files is not shown, whereas normally it is - see for example org.jacoco.core
Somewhat similar happens with SonarQube: build/reports/jacoco/test/jacocoTestReport.xml contains
so SonarQube JaCoCo Plugin tries to find file whose path ends by com/thorgil/cashbook/dataproviders/BusinessTransactionDataProvider.kt - relevant code is
however path to BusinessTransactionDataProvider.kt is src/main/kotlin/dataproviders/BusinessTransactionDataProvider.kt.
After moving this file to src/main/kotlin/com/thorgil/cashbook/dataproviders/BusinessTransactionDataProvider.kt and others to corresponding locations, you’ll see their sources in HTML report generated by JaCoCo and their coverage in SonarCloud.io :
Currently I get low coverage percentage (30%) because half of my files are throwing errors when uploading to sonarcloud.
Gettling errors like “Cannot import coverage information for file XXX. coverage data is invalid. Error: {}”
“java.lang.IllegalStateException: Line 22 is out of range in the file XXX (lines: 21)”.
It seems this issue is around for some time. I read all the remarks and posts here. I currently use jacoco maven plugin 0.8.2. This generates incorrect line numbers. At least for kotlin files. Is this wrong on jacoco side? Or doesn’t the SonarKotlin plugin translate correctly to kotlin file line numbers?
UPDATE:
I tested with jacoco maven plugin version 0.8.3-SNAPSHOT. And linenumbers are fixed. At 15-11-2018 it was merged (https://github.com/jacoco/jacoco/issues/763). No release yet from jacoco.
Whoo hoo! I guess this is also a lesson learned the hard way (don’t abuse kotlin’s liberal nature when it comes to package naming and corresponding file paths).