Lines of code utilisation by project

Having a breakdown of the number of lines of code consumed by project is not straightforward as no direct way of having it exists in SonarQube.

We will not dive into the mechanism that SonarQube uses to count the number of lines of code in a project in this guide.
Its purpose is simply to share an example script to achieve that.
You can find this script here.
The prerequisites to run this script are the following:

  • having python installed (v3.x)
  • installing the requests module (pip install requests)
  • having a user with ‘Administer System’ and ‘Browse’ permissions on projects in SonarQube

You can run the script with the following command:


The output will be something like below,

There are 4 projects in your SonarQube instance
Getting branches for all projects…
Counting the number of lines of code…
org.sonarqube:sonarscanner-maven-aggregate master 205
alex:http master 214
python test 367
sql master 11
Total nuumber of lines of code in your SonarQube instance: 797

This script is open source, feel free to contribute to it if you need.