Tuesday, June 18, 2019

Different way to analysis Project using SonarQube

1- Using Eclipse plugin SonarLint
With the help of this plugin we can analysis the project or single file directly. Plugin can be installed from marketplace
https://marketplace.eclipse.org/content/sonarlint
Image1

2- Second option is to see the report on browser using SonarQube server.
Step 1:- First download the sonarQube from https://www.sonarqube.org/downloads/
Step 2:- Start the sonarQube using C:\sonarqube-7.7\bin\windows-x86-64>StartSonar.bat
Step 3:- Open the url http://localhost:9000
Step 4:- Modify your setting.xml inside C:\apache-maven-3.3.9\conf of Maven
'<profiles>
'<profile>
'<id>sonar'</id>
'<activation>
'<activeByDefault>true'</activeByDefault>
'</activation>
'<properties>
'<!-- Optional URL to server. Default value is http://localhost:9000 -->
'<sonar.host.url>
http://localhost:9000
'</sonar.host.url>
'</properties>
'</profile>
'</profiles>
step 5:- build the maven application from eclipse using following options

Iamge2

Step 6:- See the output on the browser

Iamge3

If you get an error
Not authorized. Analyzing this project requires authentication. Please provide a user token in sonar.login or other credentials in sonar.login and sonar.password.
in this case add sonar.login and sonar.password as given below
-Dsonar.login=yourloginid -Dsonar.password=yourpassword
Image1

Image2

3-Third option is to use the mvn command on prompt to reflect the report on the localhost SonarQube Server browser
Step 1:- First create a project in the Sonar Qube server using web UI as shown below
Keep the name of the project and project key same as we had defined the project name in eclipse or VCode.
Image3Image4Image5Image6Image7
Now go the folder location on prompt and run the below command on it.

c:\siddhuworkspace\siddhu-rest-call> mvn sonar:sonar -Dsonar.projectKey=siddhu-rest-call -Dsonar.host.url=http://localhost:9000 -Dsonar.login=8b57e6a62fe18d8c72b2a6d332ceecc6ab04d2fd
Check your sonarqube localhost browser your project siddhu-rest-call will be reflected

No comments: