Analyze a project with SonarQube
CodeCharta can import project metrics from SonarQube. SonarQube can generate a wide variety of project metrics for a variety of languages. It can be used for a local analysis, or it can be added to the build pipeline. In the following the installation and usage of a local sonar server is described.
Run SonarQube Server locally
From the zip file
see also SonarQube Docs
- Download the latest version of SonarQube
- Unzip the archive (use the chosen location for the next step)
- Start the Sonar Server with
C:\sonarqube\bin\windows-x86-xx\StartSonar.bat
on Windows or/opt/sonarqube/bin/[OS]/sonar.sh
on Linux/MacOS - Open
localhost:9000
in your browser and log in with- login: admin
- password: admin
Install SonarScanner
- Download the latest version of SonarScanner
- Unzip the archive
- Add the
bin
directory to the%PATH%
(Windows) orPATH
(Linux/MacOS) environment variable
From the Docker image
You can also run SonarQube with Docker, for further information read here.
- Download and install Docker Desktop if not already present on your system
- Download the latest version of SonarQube Docker Image
- Start the Sonar Server with the following command:
$ docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:latest
- Open
localhost:9000
in your browser and log in with- login: admin
- password: admin
Install SonarScanner CLI
Also see for detailed instructions here.
- Download the latest version of SonarScanner CLI
- Add a
sonar-project.properties
file to your project’s root directory
Analyze project
After you installed SonarQube do the following steps to analyze your Project:
- Click on the plus icon to create a new project
- Specify the project key and display name
- Click the respective button to generate a token
- Specify the main language for the project
- Follow the instructions from SonarQube
When using SonarQube version >= 9.5, you need to create a user token. In your account settings select the security settings.
For further information read here
Extract project metrics from Sonar Server
To visualize your project metrics created by Sonar use CodeCharta’s sonar importer to generate a cc.json
file.
Beginner’s Guide for using SonarQube
If you are totally new to SonarQube, you are welcome to read more detailed instructions here.