ソナーがコードをスキャンする 3 つの方法
ソナースキャナーをダウンロード
ダウンロードアドレス:
https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
ソナースキャナーの構成
環境変数の構成:
構成が成功したことを確認する
コマンドラインに sonar-scanner -version と入力すると、次のインターフェイスが表示され、sonar-scanner のインストールと構成が成功したことが示されます。
ソナースキャナーの使用
1. 確認したいコードのルートディレクトリにファイルを作成しますsonar-project.properties
公式ウェブサイトの参考例:
https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner/#cconfiguring-your-project
# must be unique in a given SonarQube instance
sonar.projectKey=study
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=study
sonar.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=./src
sonar.java.binaries=./target/classes
sonar.language=java
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
2. コマンドラインからチェックするコードディレクトリに移動し、コマンドを入力します。チェック結果はsonar-scanner
ブラウザ上で直接SonarQube
確認できます。