SonarQube, it’s an required tool when you’re going though a quality work and want to maintain it with your team as well.
Below are the steps that will guide through setting up a sonar in local machine.
- Download SonarQube 5.1
- Extract the zip file
- Change sonar.properties file
- Go to sonarqube-5.1\conf\inextractractedfolder.
- find”sonar.jdbc.username” and change it to “root” (Database username you use to login)
- find “sonar.jdbc.password” and change it to “root” (Database password you use to login for root)
- go to the MySQL 5.x section of file and remove comment from “sonar.jdbc.url”
- Create a schema named “sonar” in mysql
- Run “StartSonar.bat” from folder in “sonarqube-5.1\bin\” based on your OS and architecture. i.e. “sonarqube-5.1\bin\windows-x86-64\StartSonar.bat”
- Login to Sonar
a. Now click on Login from upper right corner of the page and login with username as “admin” and password as “admin”.
b. Go to http://localhost:9000 and check if sonar is working or not. (Sometimes it may take around 2-5 minutes, after you run StartSonar.bat)
- Install Groovy plugin to Sonar (SKIP THIS STEP IF YOUR’RE ONLY WORKING WITH JAVA)
- Once logged in, click on settings from the upper menu.
- Select Update Center from System menu.
- Click on Available Plugins and search for Groovy and install it.
- Restart sonar to get the benefit of installation.
- Press Ctrl + C on cmd screen that is running the sonar server.
- Press Y when asked to terminate batch job.
- Again click on “sonarqube-5.1\bin\windows-x86-64\StartSonar.bat” to start the sonar server.
- Run Analysis on Project
- Download SonarQube Runner (v. 2.4) and extractzip file.
- Go to”sonar-runner-2.4\conf\sonar-runner.properties”anduncomment “sonar.jdbc.url” in MySQL section.
- Now set an Environement variable for “SONAR_RUNNER_HOME” and set the path upto root folder of extracted Sonar Runner.
- To test if the environment variable is set open cmd and run “echo %SONAR_RUNNER_HOME%”, if you don’t see the path to folder printed then restart your machine, it will be set then.
- Copy “sonar-runner-2.4\bin\sonar-runner.bat” to project’s root folder.
- Run the file “sonar-runner.bat” from root folder of project.
- So, now project is analyzed, you can view it on your sonar server.
- Associate your eclipse project with SonarQube
- Go to eclipse market place and search with “sonarqube”, and install SonarQube 3.4.0
- Go to Windows -> Preferences and search for “SonarQube” expand the section and go to “Servers“. Check if “http://localhost:9000” is available or not, if not then add.
- Right click on Project -> Configure -> Associate with SonarQube…
- New window for Associate with SonarQube will open. Please type project keyword against your project, that will suggest the analyzed project on sonar server – select it and click on Finish.
- Eclipse is configured with SonarQube, to analyze your local project from eclipse rightclick on project and goto SonarQube -> Analyze.