This article describes how to use SonarLint, SonarQube and SonarCloud. For the examples the Eclipse IDE is used.

1. What is SonarQube

SonarQube (formerly Sonar) is an open source platform for continuous inspection of code quality. It provides a server component with a bug dashboard which allows you to view and analyze reported problems in your source code.

Using SonarQube via Maven or Gradle is very simple and very well described on the SonarQube homepage. See http://docs.sonarqube.org/display/SCAN/Analyzing+Source+Code and its links for Maven or Gradle.

A IDE version of the SonarQube checks is called SonarLint and can be installed iin most popluar IDE, like Eclipse, VsCode or IntelliJ.

2. SonarLint for Eclipse

2.1. Installation

SonarLint is available an stand-alone extension for the Eclipse IDE.

You can install SonarLint into Eclipse via the marketplace client. The update site is https://eclipse.sonarlint.org. See Sonar on Eclipse for details.

2.2. Using SonarLint

Afterwards SonarLint analysis your files automatically if you open them. You can run its analysis for one or several projects.

sonarlint analyze10

After the analysis the SonarLint Report shows the issues the analysis found.

sonarlint analyze20

3. Installation of SonarQube

3.1. Using Docker

Running SonarQube via Docker is as simple as the following command.

$ docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqube

You can now login your local Sonar server on http://localhost:9000/ with the admin user and the admin password.

Click on: Create your first project.

This will allow you to create an access token which you batch job can use to update the project.

See http://docs.sonarqube.org/display/SONAR/Setup+and+Upgrade for an full installation of SonarQube. If you want to try out SonarQube, you can also use the official Docker image for SonarQube from https://hub.docker.com/r/_/sonarqube/

4. Usage of SonarQube

4.1. Analyse a Maven project

To analyse a Maven project use the following command:

mvn sonar:sonar   -Dsonar.host.url=http://localhost:9000   -Dsonar.login=yourkey

4.2. Create HTML reports

Your can generate HTML reports in the preview analysis mode.

mvn sonar:sonar -Dsonar.analysis.mode=preview -Dsonar.issuesReport.html.enable=true