Continuous inspection in 5 minutes with SonarQube

sonarqube-projects.png

Try SonarQube, a continuous inspection tool that supports more than 20 languages (partially charged) such as Java, JavaScript, C #, Python, PHP, in a local environment within 5 minutes. Make a note of the method.

This article is based on the macOS environment.

Install SonarQube

Install SonarQube with Homebrew.

$ brew install sonarqube

Launch SonarQube

SonarQube can be started with brew services start sonarqube.

$ brew services start sonarqube
==> Successfully started `sonarqube` (label: homebrew.mxcl.sonarqube)

Access the SonarQube dashboard

Try accessing the SonarQube dashboard from your browser. The first access will take some time.

http://localhost:9000

sonarqube-dashboard.png

Install SonarQube Scanner

Install SonarQube Scanner with Homebrew. SonarQube Scanner analyzes the project and registers the analysis results in SonarQube.

$ brew install sonar-scanner

Analyze the sample project

Clone a Java sample project based on the VideoStore, an example of Martin Fowler's Refactoring, and analyze it with SonarQube Scanner.

$ git clone https://github.com/takuya0301/videostore.git
$ cd videostore
$ ./gradlew test
$ sonar-scanner \
    -Dsonar.projectKey=videostore \
    -Dsonar.sources=src/main \
    -Dsonar.tests=src/test \
    -Dsonar.jacoco.reportPaths=build/jacoco/test.exec \
    -Dsonar.java.binaries=build/classes

Analysis parameters

Key Description
sonar.projectKey The project key specifies a unique value for each project.
sonar.sources Specify the directory containing the source files as a comma-separated path.
sonar.tests Specify the directory containing the test files as a comma-separated path.
sonar.jacoco.reportPaths Specifies the path to the report file generated by Jacoco, the Java code coverage library.
sonar.java.binaries Specify the directory containing the compiled bytecode file as a comma-separated path.

Check the analysis result of the sample project

You can check the analysis result of the sample project by accessing SonarQube from a browser.

http://localhost:9000/dashboard?id=videostore

sonarqube-videostore.png


I explained how to run SonarQube locally within 5 minutes to analyze the sample project. I think it's a good idea to consider introducing it by operating SonarQube or analyzing other projects. SonarQube Scanner also has plugins for CI tools such as Jenkins, so it is recommended to set it to work with CI tools in actual operation. If you feel like working with Jenkins, let's write an article.

References

https://docs.sonarqube.org/display/SONAR/Documentation

Recommended Posts

Continuous inspection in 5 minutes with SonarQube
"Hello, World!" With Kotlin + CLI in 5 minutes
Value object in 3 minutes
Japaneseize using i18n with Rails
G1 Garbage Collection in 3 Minutes
Java Stream API in 5 minutes
Easily develop web applications with STS and Spring Boot. In 10 minutes.