定義
SonarQubeは、コードの品質を管理するためのオープンプラットフォームであり、コード内の潜在的なエラーまたは明らかなエラーをすばやく見つけることができます。このツールのインストール、構成、および使用については、以下で説明します。
準備オーケー;
1. jdk(導入されなくなりました)
2、sonarqube:http://www.sonarqube.org/downloads/
3、SonarQube + Scanner:https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.5.zip
4. mysqlデータベース(導入されなくなりました)
SonarQubeダウンロード
ソナー公式サイト:https://www.sonarqube.org/
ソナーダウンロードリンク:https://www.sonarqube.org/downloads/
SonarQubeのインストール
事前設定条件:1. Java環境(1.8以降)
2. MySqlデータベース(5.6以降)
3. SonarQube 7.6を
ダウンロードして解凍すると、レンダリングは次のようになります。
confファイルを入力してsonar.propertiesを構成します。パラメーター情報は次のとおりです。
1.打开mysql,新建一个数据库。
2.打开sonarqube安装目录下的D:\sonar\sonarqube-5.3\sonarqube-5.3\conf\sonar.properties文件
3.在mysql5.X节点下输入以下信息
4.重启sonarqube服务,再次访问http://localhost:9000,会稍微有点慢,因为要初始化数据库信息
5.数据库初始化成功后,登录
sonar.jdbc.username=root
sonar.jdbc.password=123123
sonar.jdbc.url=jdbc:mysql://localhost:3307/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.web.port=9000
url是数据库连接地址,username是数据库用户名,jdbc.password是数据库密码,login是sonarqube的登录名,sonar.password是sonarqube的密码
binフォルダーに入ると、効果は次のようになります。
さまざまなオペレーティングシステムをサポートしています。独自の現在のオペレーティングシステムを選択してください。レンダリングは次のとおりです。
InstallNTService.bat、StartNTService.bat、StartSonar.batファイルの順に実行します。エラーがない場合は、次のURLにアクセスしてください。http:// localhost:9000正常に起動した後の効果は次のとおりです。
これまでのところ、SonarQubeは正常にインストールされています
SonarQube中国語設定
下の図のクリックシーケンスに従って、プラグインインストールページに入ります。
中国語パックを検索し、中国語言語パックをインストールします
インストールが成功した後、sonarqubeサービスを再起動し、http:// localhost:9000 /に再度アクセスして中国語のインターフェースを確認します
ソナースキャナーのインストールと使用
ソナースキャナープラグインは、ソフトウェアの分析に使用され、SonarQubeと組み合わせて使用されます
ソナースキャナーダウンロード
ダウンロードリンク:https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.0.3.778-windows.zip
解凍して使用
ソナースキャナーの設定と使用
1、打开D:\sonar\sonar-scanner-2.5\conf\sonar-runner.properties文件
2、mysql节点下输入以下信息
--------------------------------------------------------------
sonar.jdbc.url=jdbc:mysql://172.16.30.228:3306/qjfsonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.jdbc.username=gmsd
sonar.jdbc.password=gmsdtrade
--------------------------------------------------------------
注意:如果测试项目与服务器不在同一台机子,则需要添加服务器的IP:
--------------------------------------------------------------
#----- Default SonarQube server
sonar.host.url=http://XXX.XXX.XXX.XXX:9000
--------------------------------------------------------------
環境変数を設定します。
1、新建变量,name=SONAR_RUNNER_HOME。value=D:\sonar\sonar-scanner-2.5
2、打开path,输入%SONAR_RUNNER_HOME%\bin;
3、sonar-runner -version,出现以下信息,则表示环境变量设置成功
データベースの設定は上にあります、もう一度紹介してください--- "" "
confの下でsonar-scanner.propertiesを変更し、次のように構成します。
sonar.host.url=http://localhost:9000(sonar地址)
sonar.sourceEncoding=UTF-8
sonar.jdbc.url=jdbc:mysql://localhost:3307/sonarqube?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.jdbc.username=******
sonar.jdbc.password=*******
検出するプロジェクトのルートディレクトリに、次の内容で新しいsonar-project.propertiesを作成します。
sonar.projectKey=your_project(自己定义)
sonar.projectName=your_project(自己定义)
sonar.projectVersion=1.0
sonar.sources=src(代码目录)
sonar.java.binaries=target(classes文件目录,不加会报错)
sonar.language=java
sonar.sourceEncoding=UTF-8
または
# must be unique in a given SonarQube instance
sonar.projectKey=my:project
# this is the name displayed in the SonarQube UI
sonar.projectName=apiautocore
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
# If not set, SonarQube starts looking for source code from the directory containing
# the sonar-project.properties file.
sonar.sources=src
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
そのうち、projectNameはプロジェクトの名前、sourcesはソースファイルが配置されているディレクトリです。
設定が成功したら、sonarqubeサービスを開始し、cmdを開始します。
cmdにプロジェクトのルートディレクトリを入力し、次のコマンドを入力します:sonar-runner、分析が成功すると、次の画像が表示されます
http:// localhost:9000 /を開くと、ホームページに分析プロジェクトの概要図が表示されます
プロジェクトをクリックし、問題のリンクを選択すると、分析コードのバグが表示されます
最も深刻なバグの1つを選択して参照してください
次に、プロジェクトのルートディレクトリでコマンドラインを開き、sonar-scannerと入力して実行すると、検出が成功したことがわかり、検出結果がsonarホームページに表示されます。効果図は次のとおりです。