SonarQube is a code analysis tool which can be used as an aid to improving code quality. This page details how I have installed and used it for local development.
Installation
SonarQube is available as a docker instance. To pull an image from docker use
docker pull sonarqube
The instance can be run with default settings using the following command. Note that the default port is 9000
docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqube
Setup
Got to URL http://localhost:9000/ and login with default user/password admin/admin. You will be prompted with a wizard the first time you logong.
This wizzard will allows you to
- Create a token for use with projects the first time you do this. The token is used to identify you when an analysis is performed.
- Run analysis over a project. You are prompted for the language and project type, and then a command is generated - e.g. (for a maven project)
mvn sonar:sonar -Dsonar.host.url=http://localhost:9000 -Dsonar.login=a4acbabe08ab339f1ee872d9fa250418c44165a0
Code Analysis
To run analysis over a code use mvn sonar:sonar -Dsonar.host.url=http://localhost:9000 -Dsonar.login=[token] (i.e. as shown above) in the project root. You must have a vallid token. Additional tokens can be created from http://localhost:9000/admin/users - see the Tokens column in this view.
The above command will run the analysis, and the log output will contain a url to view the results - e.g.
ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/uc-transfers:uc-transfers-persistence
Top Comments