How lines of code is calculated for license purpose?

When I go to License Manager page, I can see value of lines of code analyzed.
I have few questions around how this is value is calculated:

  • SonarQube Developer edition 8.9
  • I am trying to find out how Lines of Code is calculated.
    1. If I have repository in Azure DevOps and it has two branches, b1 (2k) and b2 (4k), 4k will be used of calculation, right?
    2. I have totaled all LOCs which I got from SonarQube api, for all repositories. The total is quite less compared to whats shown on License Manager.
    3. What are the best practices to reduce total LoC?
    4. If a repository of size 4k is scanned twice (scan is done using build pipeline), the LoC count will be 8k or 4k?
    5. Is breakdown of Lines of Code on License Manager would be possible to get?


Welcome to the community!


I suspect you’re getting main branch LOC counts by default. I.E. the 2k from your example above, rather than the 4k

Make sure you’re not accidentally analyzing 3rd party code such as libraries. You should probably also eliminate generated code from analysis.

4k. We want you to get the full benefit of analysis, and you won’t do that if you’re incented to analyze infrequently. The license is not structured so that you use it up by re-analyzing the same code. Ideally you’ll analyze after every commit, and the license is structured to encourage that.

This is available via a web service in the latest versions.


Hello Ann,

Thank you very much for your response. This really helps in understanding the License LoC calculation logic.

Could you please elaborate on point no. 3? How can we avoid analyzing third party libraries? Using just
sonar.exclusions ?


Take a look at the first few sections of this page and see if it doesn’t answer the question for you. If not, let me know and I’ll try again.