一.在線安裝sonarLint
打開eclipse里的help->Eclipse Marketplace,搜索“sonar”關鍵字,目前sonar的插件是sonarlint,如下圖:
點擊“Installed”后,依次下一步即可。安裝成功后,eclipse需要重啟。
在Windows->Preferences,下可以看到SonarLint,即表示安裝成功。如下圖:
SonarLint的使用:
(1)對整個項目進行代碼檢查:右擊項目名稱,找到sonarLint,然后根據提示進行Analyze即可
(2)對單個文件進行代碼檢查:右擊要檢查的類名稱,找到sonarLint,然后根據提示進行Analyze即可
注意:對於低版本的eclipse及1.8版本下的jdk而言,是無法在線安裝的。
二.離線安裝
對於低版本的eclipse及jdk,eclipse中是不支持在線安裝sonarLint的,需要線下設置:
- 直接解壓解壓壓縮文件Sonar-runner-2.4.rar到D:\sonar-runner
- 設置SONAR_RUNNER_HOME
3.加入到PATH中
D:\sonar-runner\sonar-runner-2.4\bin;
4.修改剛解壓安裝文件
D:\sonar-runner\sonar-runner-2.4\conf下sonar-runner.properties文件
按照下方配置:
#Configure here general information about the environment, such as SonarQube DB details for example
#No information about specific project should appear here
各位,Sonar的正式服務器已更新為sonar.host.url=http://sonar.99bill.net
修改sonnar-runner conf下配置文件:
#----- Default SonarQube server
sonar.host.url=http://192.168.138.93:9000/
#----- MySQL
sonar.jdbc.url=jdbc:mysql://192.168.138.63:3306/sonar_all?useUnicode=true&characterEncoding=utf8
sonar.jdbc.username=qamp
sonar.jdbc.password=qamp
sonar.sourceEncoding=UTF-8
sonar.login=admin
sonar.password=admin
|
5.要掃描工程根目錄,新建sonar-project.properties文件
6、執行分析
進入CMD,進入工程目錄。
執行命令:sonar-runner
出現analysis successful表示分析成功。