Exporting Sonar reported issues to excel

Recently, I was asked by one of my blog reader to share an approach for exporting issues reported by Sonar to excel. Though the same can be achieved using Sonar plugins having commercial licences & may be few by open source plugins, it is as well possible to fetch the same using the webservice API exposed by the Sonar platform.

More on this webservice java API & javadoc can be found here – http://docs.sonarqube.org/display/SONAR/Using+the+Web+Service+Java+client

I have written a simple java client which makes a webservice call to Sonar platform running in my local machine & then uses Apache POI (http://poi.apache.org/download.html) to generate the corresponding excel.

Here is the java code (Note – The below code snippet is not exhaustive because of the time constraint. Currently, it just try to fetch all the Critical, Major & Minor issues of the projects analysed by Sonar. I’ll try to enhance the same in future!) –

package com.sanjit;

import java.io.FileOutputStream;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.sonar.wsclient.SonarClient;
import org.sonar.wsclient.issue.Issue;
import org.sonar.wsclient.issue.IssueClient;
import org.sonar.wsclient.issue.IssueQuery;
import org.sonar.wsclient.issue.Issues;

public class Sample {

public static void main(String args[]) {

String login = "admin";
String password = "admin";

SonarClient client = SonarClient.create("http://localhost:9000");

IssueQuery query = IssueQuery.create();
query.severities("CRITICAL", "MAJOR", "MINOR");

IssueClient issueClient = client.issueClient();
Issues issues = issueClient.find(query);
List<Issue> issueList = issues.list();

private static void createExcel(List<Issue> issueList) {
// TODO Auto-generated method stub

try {
String filename = "D:/SonarIssues.xls";

HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("FirstSheet");

HSSFRow rowhead = sheet.createRow((short) 0);
rowhead.createCell(0).setCellValue("Project Key");
rowhead.createCell(3).setCellValue("Rule Key");

for (int i = 0; i < issueList.size(); i++) {
HSSFRow row = sheet.createRow((short) i+1);

FileOutputStream fileOut = new FileOutputStream(filename);
System.out.println("Your excel file has been generated!");

} catch (Exception ex) {


You will need to put the below jars in your classpath –


11 thoughts on “Exporting Sonar reported issues to excel”

    1. Hi,
      You can use the “GET api/issues/search” which is available since sonar web service API version 3.6.

      This API takes an optional parameter called “componentKeys” to retrieve issues associated to a specific list of components sub-components (comma-separated list of component keys). A component can be a view, developer, project, module, directory or file.

      Below is an example URL –


      where “sanjit:JavaProject” is my sonar project key.

      The above URL will fetch all the issues for the given project and return as JSON.

      Note:- There exist a limitation with this API. If the number of issues is greater than 10,000, only the first 10,000 ones are returned by the web service.



  1. Hi sanjit,
    Your post helped me create an excel that can be used for our groups requirement with assignment of issues to teams. Thanks.
    Is there a way to export all the configured rules with their id, title & description into an excel? I want to be able to send this list to a few people who can filter out the really relevant ones for us.
    I tried using ProfileQuery & Profile.Rule but it doesn’t provide title & descr.


    1. Hi,
      The blog is little outdated. Now you shouldn’t be using the sonar web service java client APIs. It is soon going to be deprecated.

      More of it here ->

      Now you should directly use their web service APIs using wink or jersey libraries & then parse the JSON from the results (use JSON libraries like gson) to get the needed data in your java client program.

      For your purpose, you should be using “api/rules/search” API,

      Below is an example URL –


      The above URL will fetch all the configured sonar rules in JSON.



  2. this code only fetching few issue not all. shall i know how to get all the issue.
    excel has only 173 but issue is around 37,000.


    1. Hi Salva,
      Yes, you can retrieve issues filter by “types” as well.

      Below is a sample code which should give you all the issues filtered by type “CODE_SMELL”. Similarly, you can filter by “BUG”, “VULNERABILITY” & “SECURITY_HOTSPOT”.

      Note that the support for “types” was added from version 5.5. So, make sure you have the apt versions at client & server sides. For your reference, you can find the client side jar for version “5.6.3” over here – “https://jar-download.com/artifacts/org.sonarsource.sonarqube/sonar-ws/5.6.3/source-code”.

      Hope that helps!

      import org.sonarqube.ws.Issues;
      import org.sonarqube.ws.client.HttpConnector;
      import org.sonarqube.ws.client.WsClient;
      import org.sonarqube.ws.client.WsClientFactories;
      import org.sonarqube.ws.client.issue.SearchWsRequest;

      import java.util.ArrayList;
      import java.util.List;

      public class SonarWebClient {
      public static void main(String args[]) {

      Possible values –
      1. CODE_SMELL
      2. BUG
      List types = new ArrayList();

      HttpConnector httpConnector = HttpConnector.newBuilder()
      .credentials(“admin”, “admin”)
      WsClient wsClient = WsClientFactories.getDefault().newClient(httpConnector);

      SearchWsRequest searchWsRequest = new SearchWsRequest();

      Issues.SearchWsResponse response = wsClient.issues().search(searchWsRequest);

      List issuesList = response.getIssuesList();


  3. Page size and Page Index have changed! I managed to get it work by modifying the queryMap directly (not the best way though)

    Map queryMap = query.urlParams();
    // 500 is max val
    queryMap.put(“ps”, EncodingUtils.toQueryParam( new String[]{“”+args[1] })); // page size
    queryMap.put(“p”, EncodingUtils.toQueryParam( new String[]{“”+args[2] })); // page index
    query = query.severities(“BLOCKER”,”CRITICAL”,”MAJOR”,”MINOR”);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.