Installation on Windows Goto:- https://www.sonarqube.org/downloads/ Download Community Edition It will download a Zip file so extract that...
Installation on Windows
- Goto:- https://www.sonarqube.org/downloads/
- Download Community Edition
- It will download a Zip file so extract that file
- Open Command Prompt (Run as Administrator) and change directory to bin\windows-x86-64 and run StartSonar.bat
Installation on Mac
brew install sonar
brew install sonar-scanner
sonar console
Integrate with Maven
Prerequisites :
Java should be installed
Some IDE (Eclipse) should be installed
Maven should be installed
Step 1:- Open Eclipse and provide the workspace folder (C:\Projects\Java17 in my example).
Step 2:- File-->New--->Other-->Maven Project
Step 3:- Select the option "Create a simple project( skip archetype selection).
Step 4:- Click on Next
Step 5:- Provide below details
Group id:- com.raman
Artifact id:- sonarproj
Step 6:- Click on the Finish button
Step 7:- Goto sonar website and create a token and keep in sone file so that if required then you can refer to this token
SonarQube Website---> Administrator Menu ---> Security--->Users
Step 8:- Add sonar dependencies in pom.xml and also create a profile in maven for sonarqube and refer the sonar url and login (provide token which created in above step) details and save pom.xml file. Below is the sample of pom.xml file which I have configured in my project
Step 9:- Write some code that you want to analyze.
package com.raman;
Step 9:- Check that jar file is getting created in the target folder( should be created without any issue)
cd C:\Projects\Java17\sonar
mvn package
Step 10:- To add this project into sonar for code analysis.
mvn clean package sonar:sonar
Step 11:- You should be able to see sonar project in sonar web portal.
Step 12:- Open the project in Sonar webpage and check the Overview. It may be passed in status ( if there is no major error) and Failed if the code error is not to be ignored.
Step 13:- Check the Code Smell, Then modify the application code according to the severity of the code smell issues, you can change the severity (like from Major to Info) if you think that it can be ignored or should be handled properly.
COMMENTS