How Do You Analyze Code with SonarQube?

Problem scenario
You want to utilize SonarQube to do some analysis of some code. What do you do?

This assumes you have SonarQube and SonarQube Scanner (aka sonar-scanner) installed. If you need assistance with either of these, see this link to install SonarQube or this link to install sonar-scanner.


  1. Place the source code file (e.g., in directory on the back-end of a server with Sonar-Scanner.
  2. The file should refer to the directory with the code in the stanza sonar.sources= stanza. The path after the equals sign is relative to the directory the file is in. So if you have a subdirectory named "contint" in the same directory that the file, your stanza will look like this:


  1. From the directory with, run the sonar-scanner -X command.
  2. Go to the web UI for SonarQube. Log in. Go to Projects. Click on the Project associated with the name specified in the file.
  3. Optional step if you only want to analyze code for one programming language. In the file, the sonar.language stanza should be specific to the code you want to analyze exclusively. There are codes (or abbrieviated symbols) for each languages. If you run the "sonar-scanner -X" on the back-end, you may see the different codes amongst other output. For three languages, here are the codes, but do not use the quotes:
    For Python, the code is "py". For C#, the code is "cs". For java, the code is "java".

Here is an example of the sonar.language stanza for Python:


If you want SonarQube Scanner to analyze each programming language, omit or comment out the sonar.language stanza

Leave a comment

Your email address will not be published. Required fields are marked *