5
votes

I'm having some issues when trying to import Jacoco code coverage to SonarQube.

I am using SonarQube with Jacoco for importing test coverage results (https://docs.sonarqube.org/display/PLUG/Java+Unit+Tests+and+Coverage+Results+Import). Everything has worked well until i have forEach block in some method.

ERROR: Cannot import coverage information for file, coverage data is invalid. 
java.lang.IllegalStateException: Line 29 is out of range in the file (lines: 28)

If I remove forEach file then test coverage is correctly generated, but with forEach I get 0% coverage.

This happens only when i integrate it with sonarqube, if i run jacoco locally it works perfectly.

We use SonarQube Scanner 3.3.0.1492, SonarQube server 7.5.0.

1

1 Answers

10
votes

Search in Google by keywords sonarqube kotlin jacoco and

is out of range in the file

reveals following page https://community.sonarsource.com/t/sonar-kotlin-coverage-fails-due-to-line-is-out-of-range-errors/3201/18 , which states that problem was fixed in JaCoCo version 0.8.3 And which contains link to page https://github.com/jacoco/jacoco/issues/763 , which in its turn contains quite expressive explanation of problem, including explanations of why it affects SonarQube.

So make sure that you use JaCoCo version 0.8.3 or even better latest, which is 0.8.7 as of 8 September 2021.