Fetch SonarQube Report using Java project with Sonar rest api

Hi ,
I want to fetch SonarQube report from java project. is there any SonarQube api available so that I can use it and fetch data like bugs, code smells, duplications using api?

Hey! I am maintaining an external tool called Sorald. Its main purpose is to repair violations of SonarQube.

However, you can also use it to get a report of all violations. Run it as a maven plugin like so:

mvn se.kth.castor:sorald:mine -DstatsOutputFile=stats.json

Run the above command at the root of your project and you will get a list of violations detected output to the STDOUT. Also, stats.json will give you a more detailed report in JSON format.

Thank you aman for your valuable response.
I think the method you have suggested will give the sonar report for just my project only.
However, my requirement is slightly different.
In my java project, i m looking forward to configure some sonar api, which can give me reports from all the project which have configured sonar in them based on the parameters i pass from the request(eg. project name).

give me reports from all the project which have configured sonar in the

Okay. Someone from SonarSource should answer your question better then :slight_smile:

If you do not find such an API, you could mimic such a functionality with my tool.

  1. Clone the repository locally.
  2. Run mvn se.kth.castor:sorald:mine -DstatsOutputFile=stats.json.
  3. Parse stats.json file.
  4. Return the response to the function from where the API was called.

Steps 1-3 could be a part of a subprocess.

1 Like