Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue when trying to import Jacoco code coverage to SonarQube: Cannot import coverage information for file, coverage data is invalid

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.

like image 547
rerashhh Avatar asked May 14 '19 08:05

rerashhh


People also ask

How do I get code coverage in SonarQube?

SonarQube itself does not calculate coverage. To include coverage results in your analysis, you must set up a third-party coverage tool and configure SonarQube to import the results produced by that tool. Below, you'll find guidelines and resources, as well as language- and tool-specific analysis parameters.

What is difference between JaCoCo and SonarQube?

SonarQube has a broader approval, being mentioned in 163 company stacks & 271 developers stacks; compared to JaCoCo, which is listed in 5 company stacks and 11 developer stacks.


1 Answers

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.

like image 78
Godin Avatar answered Nov 15 '22 09:11

Godin