Easy guide to setup SonarQube and SonarLint
3 min readNov 19, 2020
Introduction
This article will demonstrate how to setup SonarQube, SonarScanner and SonarLint. It is an open-source platform, can help you to identify different issues related to your code and test coverage.
How will you setup and run analysis?
Prerequisites (Here, I have mentioned actual Technology details of my setup)
- Windows32 /x64
- Java 1.8
- JDK 8
- Node
- Angular / React
Step 1: Let’s configure SonarQube
- Download latest LTS (Long-term Support): SonarQube 6.7.x form https://www.sonarqube.org/downloads/
- Unzip the downloaded folder.
- To start SonarQube open sonarqube-6.7.6/bin/windows-x86-XX/StartSonar.bat
- The default port is 9000 so you will be able to access it on http://localhost:9000
- To login as Administrator default credentials are admin/admin
Step 2 : Configure SonarScanner
- Download https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492-windows.zip
- Unzip the downloaded folder.
- Open file 'sonar-scanner-cli-3.3.0.1492-windows\sonar-scanner-3.3.0.1492-windows\conf\sonar-scanner.properties'
- Uncomment the line "sonar.host.url=http://localhost:9000" by removing starting character # on the line
- Set folder path in environment variable, e.g. D:\sonar-scanner-cli-3.3.0.1492-windows\bin;
- To check the SonarScanner working open command prompt and run command 'sonar-scanner.bat -h'. It will give you available command options.
sonar.projectKey=projectKey# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.sonar.projectKey=projectKey# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.sonar.projectName=Project Namesonar.projectVersion=1.0# Path is relative to the sonar-project.properties file. Replace “\” by “/” on Windows.# This property is optional if sonar.modules is set.sonar.sources=.# Encoding of the source code. Default is default system encoding#sonar.sourceEncoding=UTF-8
Step 3: Run your project analysis
- Now you can run analysis, by using the command ‘sonar-scanner’. Run this command in your project root directory terminal.
- To avoid “Java heap space error or java.lang.OutOfMemoryError” error, set SONAR_SCANNER_OPTS=-Xmx512m as environment variable.
- You can see an analysis report on SonarQube dashboard (http://localhost:9000) in the following way.
Step 4: And configure SonarLint
- In Visual Studio Code, go to extensions option and install SonarLint
- SonarLint will help us to detect code quality issues.
- To connect SonarLint to SonarQube, go to File->Preferences->Settings->Search for sonarlint
- Update workspace settings as mentioned below,
{“sonarlint.connectedMode.project”: {“serverId”: “my_sonarqube”, // Connection defined in sonarlint.connectedMode.servers“projectKey”: “projectKey” // Project key in SonarQube/SonarCloud},“sonarlint.connectedMode.servers”: [{“serverId”: “my_sonarqube”, // Connection identifier“serverUrl”: “http://localhost:9000", // SonarQube/SonarCloud URL — https//sonarcloud.io for SonarCloud“token”: “4a53d5342382a9079369f0fb9e46bd14b2f479a4” // User token — generated in SonarQube/SonarCloud in My Account>Security}]}
Please add a comment, if you are looking for any related solution or option.