How to calculate individual file coverage for java projects

I’m using sonarqube version 7.9.

We have a common main branch being used as target. Since, multiple teams are using the same branch to commit to, and the new loc aggregate rule is set to >=80%.

Sometime, a PR gets merged with individual file having coverage less than 80 (due to being averaged out to be more than 80, because of 100% coverage in other files), but when new PR comes in it fails due to older commit from main showing aggregate coverage less than 80.
( For eg, PR1 gets merged with 2 files with coverage 75% , 100% respectively, PR2 has good enough coverage but 1st file from main now fails with less coverage)

Is there any way to set a rule to check coverage >=80% per file ?

Hi,

Welcome to the community!

First, your version is past EOL. You should upgrade to either the latest version or the current LTS at your earliest convenience. Your upgrade path is:

xxx → 7.9.6 → 8.9.2 → 9.1 (last step optional)

You may find the Upgrade Guide and the LTS-to-LTS Upgrade Notes helpful. If you have questions about upgrading, feel free to open a new thread for that here.

Regarding your actual question, what you’re encountering is what I call the “fudge factor”. Coverage requirements aren’t enforced when there are fewer than 20 changed lines. Once you upgrade to 9.1, you’ll find a setting to turn that behavior off & always enforce coverage requirements.

 
HTH,
Ann

Thank you Ann ! Will upgrade to the latest version.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.