How to call sonar api from my java code

iam using sonar latest i want initiate the sonar qube api from java actual requirement is take the ststic report just giving the project loaction(ex:D://java project) like this.if u have any possiblity please let me know.

thanks in advance.



Hi yamuna,

Welcome to the community.

What you’ve described won’t work. I suggest you take a look at the scanner docs:

If you don’t use Gradle or Maven, you’ll also want to take a look at the language-specific docs:


is there any restapi available in sonarQube?

Yes, Sonarqube provides a web api, see the web api link
in the footer of your instance or for all details.
See Vulnerabilities report from API for some Groovy snippets using the web api.

1 Like

any api is support to get only report just giving project path?

No, there is no web api call that takes a project file path as parameter.
You have to write your own script/plugin that makes use of the Sonarqube web api.
Also did you read about the sonar-cnes-report and Governance plugin in this post ?

1 Like

if you have any sample code to develop own plugin please attach this conversaion.

Just to be sure you did understand Ann’s answer.
You may use the Sonarqube web api to set configuration and to get all details for existing
Sonarqube projects or your Sonarqube instance.
Those Sonarqube projects come to live after a Sonarqube analysis report is uploaded by
a Sonar scanner - Ann mentioned the existing scanners for maven, gradle, cli, ant, there is also
a Jenkins plugin.
The scanner runs typically inside Jenkins pipelines after the build stage.
After the analysis is done, the scanner uploads a report archive to Sonarqube server.
Sonarqube server evaluates the report, writes the results to database (see background tasks)
and sends webhooks to configured services (Jenkins …).

Only after that it makes sense to use the web api to get the results / metrics you’re after to create
your own reports / contents (pdf, cvs, …).
Also it’s possible the Sonarqube web ui is already sufficient for your needs !?
Project dashboards show all the metrics and there are also additional plugins.
i.e. i recommend the free SoftVis3D plugin for a code city view, which is great :ok_hand: :star_struck:

For plugin development:

see documentation

and github plugin example

and existing plugins, i.e.

1 Like

hi i need some clarification in file.using that properties file can i trigger the particular project location(d://project)…and generate the sonar report for that project is it possible?or else how can i set up the file?


from your latest posting it seems the question is not about using the Sonarqube api but more like
how to do a Sonarqube analysis for a java project !?
What build tool do you use ? Maven, Gradle, Ant … ?

The settings like sonar.sources are set on scanner side, mostly inside a CI server
as Jenkins. With Maven you don’t have to set much properties, it simply works.

iam using maven build tool.

Then use the sonarqube doc about Maven Scanner

mvn has to run with Java 8

there’s also an example here

i have one more to exclude the root project source classes in the multi module configuraion.for example :- project (root)
-projectB here i want exclude project(root) classes in the there any possible?

Please create a new topic if new question(s).

1 Like

How can we generate a report of a analysed project on the dashboard using web api in the community version of the sonarqube.

A post was split to a new topic: Analyze XML on the fly