答案 0 :(得分:3)
只需将&format=json
添加到参数中即可。
请参阅http://docs.sonarqube.org/display/SONARQUBE43/Web+Service+API#WebServiceAPI-ResponseFormats
答案 1 :(得分:1)
回答您的问题如何从外部评论中致电:
如果要从Java程序调用SonarQube Web服务API,可以使用Apache HTTP Client:
public static void main(String[] args) throws ClientProtocolException, IOException {
HttpGet httpGet = new HttpGet("http://localhost:9000/api/resources?metrics=lines");
try(CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = httpClient.execute(httpGet);) {
System.out.println(response.getStatusLine());
HttpEntity entity = response.getEntity();
System.out.println(EntityUtils.toString(entity));
}
}
在这种情况下,它会在SonarQube上打印所有项目,另外还会显示指标"行"。您可以向列表中添加多个指标,用逗号分隔:
"http://localhost:9000/api/resources?metrics=lines,blocker_violations"