# SonarKotlin code coverage

**URL:** <https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269>\
**Category:** SonarQube Cloud\
**Tags:** jacoco, kotlin, coverage\
**Created:** [July 24, 2018, 1:10pm UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269 "2018-07-24T13:10:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gdesmaziers](https://avatars.discourse-cdn.com/v4/letter/g/9dc877/32.png) [@gdesmaziers](https://community.sonarsource.com/u/gdesmaziers)\
**Post date:** [July 24, 2018, 1:10pm UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/1 "2018-07-24T13:10:36Z")

</div>

Hi,

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).

Jacoco configuration :  
property “sonar.jacoco.reportPaths”, “${project.buildDir}/jacoco/testDebugUnitTest.exec”

Version used:  
sonar gradle plugin 2.6.2  
SonarCloud

Is there another way to use the result of jacoco analysis ?

---

<div class="post-metadata">

**Author:** ![Alexandre\_Gigleux](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alexandre_gigleux/32/26_2.png) [@Alexandre\_Gigleux](https://community.sonarsource.com/u/Alexandre_Gigleux)\
**Post date:** [July 24, 2018, 2:46pm UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/4 "2018-07-24T14:46:22Z")

</div>

Hello Grégory,

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](https://jira.sonarsource.com/browse/MMF-1362) for more details.

Regards

---

<div class="post-metadata">

**Author:** ![gdesmaziers](https://avatars.discourse-cdn.com/v4/letter/g/9dc877/32.png) [@gdesmaziers](https://community.sonarsource.com/u/gdesmaziers)\
**Post date:** [September 12, 2018, 9:24am UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/5 "2018-09-12T09:24:03Z")

</div>

Hi Alexandre,

I see that the ticket is currently in Test. Do you have a plan released date for the support of Jacoco reports in SonarSource ?

Thanks

---

<div class="post-metadata">

**Author:** ![jakalesmana](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/jakalesmana/32/1067_2.png) [@jakalesmana](https://community.sonarsource.com/u/jakalesmana)\
**Post date:** [September 27, 2018, 12:18pm UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/6 "2018-09-27T12:18:55Z")

</div>

Hi Alexandre,

I already tried to send Kotlin Code Coverage ([https://jira.sonarsource.com/browse/MMF-1362](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

Thank you.

---

<div class="post-metadata">

**Author:** ![robstoll](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/robstoll/32/1077_2.png) [@robstoll](https://community.sonarsource.com/u/robstoll)\
**Post date:** [October 9, 2018, 12:56pm UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/7 "2018-10-09T12:56:32Z")

</div>

jacoco reports are still not picked up with `sonar.coverage.jacoco.xmlReportPaths` as explained here:  
[https://docs.sonarqube.org/display/PLUG/Kotlin+Coverage+Results+Import](https://docs.sonarqube.org/display/PLUG/Kotlin+Coverage+Results+Import)

is this feature not yet available on SonarCloud?

_Edit_ Tt tries to pick it up but seems to have problems due to line-number mismatches which is quite common in kotlin due to inline functions and such ☹

---

<div class="post-metadata">

**Author:** ![nicodewet](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/nicodewet/32/1215_2.png) [@nicodewet](https://community.sonarsource.com/u/nicodewet)\
**Post date:** [October 15, 2018, 10:48pm UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/8 "2018-10-15T22:48:51Z")

</div>

Excuse my ignorance but is this something that needs to be rolled out to [sonarcloud.io](http://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](http://sonarcloud.io) and my gradle.properties has: systemProp.sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/test/jacocoTestReport.xml

---

<div class="post-metadata">

**Author:** ![aldair861101](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/aldair861101/32/8197_2.png) [@aldair861101](https://community.sonarsource.com/u/aldair861101)\
**Post date:** [October 15, 2018, 11:03pm UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/9 "2018-10-15T23:03:18Z")

</div>

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.

property “sonar.coverage.jacoco.xmlReportPaths”, “build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml”

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.

My project is Android + gradle + kotlin.

---

<div class="post-metadata">

**Author:** ![jakalesmana](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/jakalesmana/32/1067_2.png) [@jakalesmana](https://community.sonarsource.com/u/jakalesmana)\
**Post date:** [October 16, 2018, 4:51am UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/10 "2018-10-16T04:51:04Z")

</div>

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.

Regards

---

<div class="post-metadata">

**Author:** ![Alexandre\_Gigleux](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alexandre_gigleux/32/26_2.png) [@Alexandre\_Gigleux](https://community.sonarsource.com/u/Alexandre_Gigleux)\
**Post date:** [October 16, 2018, 6:18am UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/11 "2018-10-16T06:18:35Z")

</div>

Hello,

I confirm SonarJaCoCo 1.0.0 is installed on [SonarCloud.io](http://SonarCloud.io) ([https://sonarcloud.io/api/plugins/installed](https://sonarcloud.io/api/plugins/installed)) and I’m waiting for the 1.0.1 to be installed very soon to handle the case described in [https://jira.sonarsource.com/browse/JACOCO-3](https://jira.sonarsource.com/browse/JACOCO-3)

Alex

---

<div class="post-metadata">

**Author:** ![aldair861101](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/aldair861101/32/8197_2.png) [@aldair861101](https://community.sonarsource.com/u/aldair861101)\
**Post date:** [October 17, 2018, 1:05am UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/13 "2018-10-17T01:05:07Z")

</div>

Hi Alexandre,

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](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.

Thanks!

---

<div class="post-metadata">

**Author:** ![Alexandre\_Gigleux](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alexandre_gigleux/32/26_2.png) [@Alexandre\_Gigleux](https://community.sonarsource.com/u/Alexandre_Gigleux)\
**Post date:** [October 17, 2018, 7:28am UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/14 "2018-10-17T07:28:47Z")

</div>

Hello Manuel,

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.

Once [https://github.com/jacoco/jacoco/issues/763](https://github.com/jacoco/jacoco/issues/763) will be fixed on JaCoCo side, I do expect these messages to disappear.

Regards

---

<div class="post-metadata">

**Author:** ![aldair861101](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/aldair861101/32/8197_2.png) [@aldair861101](https://community.sonarsource.com/u/aldair861101)\
**Post date:** [October 17, 2018, 10:24pm UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/15 "2018-10-17T22:24:47Z")

</div>

Oh, I see. Then this is a jacoco issue. Nothing to do with Sonar.

Thank you very much for your clarification!

---

<div class="post-metadata">

**Author:** ![Alexandre\_Gigleux](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alexandre_gigleux/32/26_2.png) [@Alexandre\_Gigleux](https://community.sonarsource.com/u/Alexandre_Gigleux)\
**Post date:** [October 25, 2018, 9:51am UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/16 "2018-10-25T09:51:48Z")

</div>

FYI, SonarJaCoCo 1.0.1 and SonarKotlin 1.2.1 are now installed on [SonarCloud.io](http://SonarCloud.io)

---

<div class="post-metadata">

**Author:** ![nicodewet](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/nicodewet/32/1215_2.png) [@nicodewet](https://community.sonarsource.com/u/nicodewet)\
**Post date:** [November 20, 2018, 1:46am UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/17 "2018-11-20T01:46:14Z")

</div>

Does anyone have a working sample project with gradle + kotlin + [sonarcloud.io](http://sonarcloud.io)?

I’m at the point where I’m more than willing to part with cash just for a working configuration.

I have an apparently broken configuration here: [https://gitlab.com/nicodewet/cashbook](https://gitlab.com/nicodewet/cashbook)

---

<div class="post-metadata">

**Author:** ![Godin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/godin/32/122_2.png) [@Godin](https://community.sonarsource.com/u/Godin)\
**Post date:** [November 21, 2018, 8:51pm UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/18 "2018-11-21T20:51:38Z")

</div>

> [@nicodewet](#):
>
> I’m at the point where I’m more than willing to part with cash just for a working configuration.
> 
> I have an apparently broken configuration here: [https://gitlab.com/nicodewet/cashbook](https://gitlab.com/nicodewet/cashbook)

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](https://www.jacoco.org/jacoco/trunk/coverage/org.jacoco.core/org.jacoco.core/index.source.html)

Somewhat similar happens with SonarQube: `build/reports/jacoco/test/jacocoTestReport.xml` contains

```auto
...
<package name="com/thorgil/cashbook/dataproviders/">
  ...
  <sourcefile name="BusinessTransactionDataProvider.kt">
...

```

so SonarQube JaCoCo Plugin tries to find file whose path ends by `com/thorgil/cashbook/dataproviders/BusinessTransactionDataProvider.kt` - relevant code is

> <https://github.com/SonarSource/sonar-jacoco/blob/65c55e41e32c114704fd597ccea91fc55becb4ec/src/main/java/org/sonar/plugins/jacoco/FileLocator.java#L44-L46>

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](http://SonarCloud.io) :

 ![Coverage_on_New_Code_-cashbook-_Evgeny_Mandrikov](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/2X/8/8238ae781fed01e300bd0550ddab5a59dca5ba99.png)

---

<div class="post-metadata">

**Author:** ![ivpusic](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ivpusic/32/1668_2.png) [@ivpusic](https://community.sonarsource.com/u/ivpusic)\
**Post date:** [November 22, 2018, 1:55am UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/19 "2018-11-22T01:55:14Z")

</div>

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)”.

I am using gradle + kotlin + spring boot.

Did anybody solved this?

---

<div class="post-metadata">

**Author:** ![mptardy](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@mptardy](https://community.sonarsource.com/u/mptardy)\
**Post date:** [December 17, 2018, 9:28am UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/20 "2018-12-17T09:28:23Z")

</div>

Facing the same issue. Does anybody have a solution for that?

I’ve checked the JaCoCo HTML Reports and it looks correct.

---

<div class="post-metadata">

**Author:** ![marceldekoster](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@marceldekoster](https://community.sonarsource.com/u/marceldekoster)\
**Post date:** [December 17, 2018, 12:56pm UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/21 "2018-12-17T12:56:36Z")

</div>

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](https://github.com/jacoco/jacoco/issues/763)). No release yet from jacoco.

@Alexandre_Gigleux You were right. It is fixed

---

<div class="post-metadata">

**Author:** ![nicodewet](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/nicodewet/32/1215_2.png) [@nicodewet](https://community.sonarsource.com/u/nicodewet)\
**Post date:** [January 7, 2019, 10:53pm UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/23 "2019-01-07T22:53:43Z")

</div>

Thank you so much for helping me with this. I was at my wits end. I owe you a beer at the very least.

I’ve moved the files to the correct path, as expected by the SonarQube JaCoCo plugin, and it now works, coverage is showing up on [sonarcloud.io](http://sonarcloud.io) for [https://gitlab.com/nicodewet/cashbook](https://gitlab.com/nicodewet/cashbook)

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).

---

<div class="post-metadata">

**Author:** ![ogallon](https://avatars.discourse-cdn.com/v4/letter/o/2bfe46/32.png) [@ogallon](https://community.sonarsource.com/u/ogallon)\
**Post date:** [February 21, 2019, 3:18pm UTC](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269/24 "2019-02-21T15:18:18Z")

</div>

> [@marceldekoster](#):
>
> jacoco

For me the issue with the line number get fixed adding  
jacoco {  
 toolVersion = “0.8.3”  
 reportsDir = file(“$buildDir/reports”)  
}

[Next page](https://community.sonarsource.com/t/sonarkotlin-code-coverage/1269.md?page=2)
