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 with Homebrew.
$ brew install sonarqube
SonarQube can be started with brew services start sonarqube
.
$ brew services start sonarqube
==> Successfully started `sonarqube` (label: homebrew.mxcl.sonarqube)
Try accessing the SonarQube dashboard from your browser. The first access will take some time.
http://localhost:9000
Install SonarQube Scanner with Homebrew. SonarQube Scanner analyzes the project and registers the analysis results in SonarQube.
$ brew install sonar-scanner
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
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. |
You can check the analysis result of the sample project by accessing SonarQube from a browser.
http://localhost:9000/dashboard?id=videostore
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.
https://docs.sonarqube.org/display/SONAR/Documentation
Recommended Posts