![Forrest logo](/images/logo.png)
sonar-scanner:tldr:91cf0
The command "sonar-scanner" is used to run the SonarScanner tool, which is a command-line tool for analyzing code quality. SonarScanner is a part of the SonarQube platform, which is an open-source tool used for continuous inspection of code quality.
When you run the "sonar-scanner" command, it initiates the scanner to analyze your codebase and gather various code metrics and quality-related information. It typically performs the following steps:
-
Reads the configuration: The SonarScanner reads a configuration file (typically named "sonar-project.properties") present in your project directory. This file contains various settings like the project key, project name, source directories, exclusions, SonarQube server details, and more.
-
Compiles the code (if needed): If your project requires compilation (e.g., for Java projects), the SonarScanner might invoke the appropriate compiler to compile your code.
-
Analyzes the code: The SonarScanner performs a static code analysis by running various analyzers, plugins, and rules provided by SonarQube. It scans your source code, identifies issues, and measures code metrics such as code coverage, code duplication, complexity, maintainability, security vulnerabilities, and other quality-related aspects.
-
Sends the analysis report to SonarQube server: After completing the code analysis, the SonarScanner sends the generated analysis report to the SonarQube server, either locally or remotely. The server processes this report and stores the results, which can be accessed through the SonarQube user interface.
Overall, the "sonar-scanner" command allows developers to incorporate code quality analysis as a part of their development workflow. It helps improve code maintainability, identify bugs, security vulnerabilities, and follow best practices for developing high-quality software.