Setup SonarQube, postgresql and Sonar Scanner on windows for static analysis

Glitter Zhang
2 min readJun 13, 2024

--

  1. Documents:
    https://docs.sonarsource.com/sonarqube/latest/c

2. Three components:
- Analyzer | A client application that analyzes the source code to compute snapshots.
- Database | Stores configuration and snapshots.
- Server | Web interface that is used to browse snapshot data and make configuration changes.

3. Prerequisites:
1. A 64-bit system.
2. A Java runtime environment:
Oracle JRE or OpenJDK.
Minimum version: Java 17. https://www.oracle.com/java/technologies/downloads/#jdk17-windows

4. Download SonarQube and Sonar Scanner
- SonarQube :https://www.sonarsource.com/products/sonarqube/downloads/
- Sonar Scanner:https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner/

5. Download postgreSQL
https://www.postgresql.org/download/windows/

6. Connect SonarQube with PostgreSQL
- create database in PostgreSQL:sonar
- create a user in PostgreSQL:sonar pw: 1234
in directory “~\sonarqube-10.5.1.90531\conf”
set

sonar.jdbc.url=jdbc:postgresql://localhost/sonar?currentSchema=public
sonar.jdbc.username=sonar
sonar.jdbc.password=1234


7. Load SonarQube
— click **StartSonar.bat** under “C:\Users\xx\sonarqube-10.5.1.90531\bin\windows-x86–64\”

- open web with http://localhost:9000

8. Create Project
8.1. creat project key

8.2. Use `global setting`

8.3. Set up the way of analysis- we use Locally

8.4. Generate the token

8.5. Run analysis, our system is windows and all code are developed with python.

8.6. Before you run the analysis,set the proporties in sonar.properies in directory “~\sonarqube-10.5.1.90531\conf”
sonar.login=admin
sonar.password=adminpassword
sonar.projectKey=test
sonar.projectName=test
sonar.projectVersion=1.0
sonar.sources=~\projectdirectory
sonar.projectBaseDir=\projectdirectory
sonar.sourceEncoding=UTF-8


8.7. Execute the above commands in step 5 “sonar-scann.bat ….” in your project’s folder .
8.8. If succeed, the result will be displayed on the dashbord.

Ref:

https://github.com/glitterzhang/SonarQube_postgresql_windows/

--

--

Glitter Zhang
0 Followers

Optimization, Data Science, Computer Vision, AI