SonarQube代码质量管理工具安装与使用(sonarqube5.1.2 + sonar-runner-dist-2.4 + MySQL5.x)
1. SonarQube安裝(sonarqube5.1.2 + sonar-runner-dist-2.4)
1.1 前提條件
1) 已安裝Java環(huán)境(version:1.7+)
2) 已安裝MySQL數(shù)據(jù)庫(version:5.x)
下載SonarQube: http://www.sonarqube.org/downloads/
下載Sonar-Runner: http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip
中文補(bǔ)丁包下載:https://github.com/SonarCommunity/sonar-l10n-zh
3) MySQL數(shù)據(jù)庫配置
執(zhí)行數(shù)據(jù)庫腳本,創(chuàng)建數(shù)據(jù)庫及用戶:
CREATE?DATABASE?sonar?CHARACTER?SET?utf8?COLLATE?utf8_general_ci;?
CREATE?USER?'sonar'?IDENTIFIED?BY?'sonar';
GRANT?ALL?ON?sonar.*?TO?'sonar'@'%'?IDENTIFIED?BY?'sonar';
GRANT?ALL?ON?sonar.*?TO?'sonar'@'localhost'?IDENTIFIED?BY?'sonar';
FLUSH?PRIVILEGES;
1.2 安裝Sonar?Server
1) 將下載的sonarqube-5.1.2.zip包解壓至D:\sonar\sonarqube-5.1.2;
2) 修改配置文件D:\sonar\sonarqube-5.1.2\conf\sonar.properties,進(jìn)行配置數(shù)據(jù)庫設(shè)置
1.3 啟動(dòng)Sonar Server服務(wù)
Sonar目前支持Linux/Macosx/Solaris/Windows等操作系統(tǒng)。以Windows?32位操作系統(tǒng)為例,目錄切換至D:\sonar\sonarqube-5.1.2\bin\windows-x86-32目錄(32對(duì)應(yīng)jdk7_32bit 而非windows_32bit),運(yùn)行StartSonar.bat文件啟動(dòng)服務(wù)。
?
1.4 訪問Sonar Server
訪問地址:http://172.20.28.35:9000/ 或者 http://localhost:9000/
其中,172.20.28.35為服務(wù)器的IP?
1.5 Installing SonarQube in Eclipse(安裝插件[非必須項(xiàng)],可以先忽略1.1-1.4步驟)
| Plugin | 3.4 | 3.5 |
| SonarQube | 3.6+ | 4.2+ |
| Eclipse | 3.7.x, 3.8.x, 4.2.x, 4.3.x, 4.4.x, 4.5.x | 4.2.x, 4.3.x, 4.4.x, 4.5.x |
| Supported Plugins / Languages | Java | See?Features details |
Installation: If a previous version of?Eclipse SonarQube is already installed, you can update it.?Go to?Help > Check for Updates.
To install this plugin in your Eclipse IDE:
Go to?Help > Eclipse Marketplace...?and search for "SonarQube"
Detail link: http://docs.sonarqube.org/display/SONAR/Installing+SonarQube+in+Eclipse?
2. Sonar Runner
2.1 安裝Sonar?Runner
解壓sonar-runner-dist-2.4.zip到任意目錄,為了方便,將安裝包解壓到D:\sonar-runner-2.4下。
2.2 配置環(huán)境變量
1) 打開“系統(tǒng)屬性”對(duì)話框,點(diǎn)擊“環(huán)境變量”,進(jìn)入環(huán)境變量對(duì)話框。
2)?在“系統(tǒng)變量(S)”下點(diǎn)擊“新建(W)...”,在編輯系統(tǒng)變量對(duì)話框中添加SONAR_RUNNER_HOME變量。
3) 在“系統(tǒng)變量(S)”下找到“Path”,點(diǎn)擊“編輯(I)...”,在編輯系統(tǒng)變量對(duì)話框中“變量值(V):”輸入框內(nèi)容未尾添加、“;%SONAR_RUNNER_HOME%\bin”,點(diǎn)確定。
4) 按下圖所示命令進(jìn)行驗(yàn)證環(huán)境變量是否配置成功,如果展示結(jié)果如下圖所示,則表示配置成功。
?
2.3 配置Sonar Runner
編輯D:\sonar-runner-2.4\conf\sonar-runner.properties,配置指定的Sonar?Server地址、數(shù)據(jù)庫URL、數(shù)據(jù)庫用戶名及密碼、Sonar?Server用戶名及密碼
?
2.4 配置sonar-project.properties
在項(xiàng)目源碼的根目錄下創(chuàng)建sonar-project.properties配置文件
Multi-module Project
There are two ways to define a multi-module structure in SonarQube:
| ? | Using the given file structure... | ... with the given 'properties' files | ||||||
| Way #1 Set all the configuration in the properties file in the root folder | ? | "MyProject/sonar-project.properties" file content
| ||||||
| Way #2 Set the configuration in multiple properties files | ? | "MyProject/sonar-project.properties" file content
"MyProject/module1/sonar-project.properties" file content
"MyProject/module2/sonar-project.properties" file content
|
?
Detail link: http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Runner?
2.5 代碼掃描
切換到項(xiàng)目源碼根目錄,執(zhí)行以下命令:sonar-runner
掃描結(jié)果中出現(xiàn)“EXCUTION?SUCCESS”字樣則表示代碼掃描成功。
??
2.6 查看代碼掃描結(jié)果
http://localhost:9000/
?
2.7 補(bǔ)充說明
在實(shí)際應(yīng)用過程中,可能會(huì)遇到報(bào)JVM空間不夠或內(nèi)存溢出的情況,為了解決此問題,可以按下文所示方法通過修改批處理腳本D:\sonar-runner-2.4\bin\sonar-runner.bat文件即可。
根據(jù)實(shí)際情況并參照下圖所示修改sonar-runner.bat文件中第77行。
??
3. 案例分析
默認(rèn)只有java ?plugin。添加javascript,jsp(web)檢測(cè),需下載相關(guān)插件
link:http://docs.sonarqube.org/display/PLUG/Web+Plugin
MyProject:
sonar-project.properties內(nèi)容如下:
?
Main Dashboard: 主要的信息展示
Duplications: 重復(fù)率比重
Complexity:復(fù)雜度
?
?
Configure widgets:布局控件
SQALE Rating:Software Quality Assessment based on Lifecycle Expectations Rating?基于生命周期期望的軟件質(zhì)量模型評(píng)價(jià)
Debt:技術(shù)債務(wù)(修復(fù)所有issues所用的時(shí)間代價(jià))
Issues: Blocker/Critical/Major/Minor/Info 問題的級(jí)別,依次從高級(jí)到低級(jí)。
???
如下圖:點(diǎn)擊issues 選擇Critical級(jí)別,右側(cè)會(huì)有一個(gè)列表,點(diǎn)擊文件進(jìn)入。
?
在紅色箭頭處點(diǎn)擊展開,會(huì)有相關(guān)信息提示。
???
4. 參考文檔
1.如何搭建Sonar代碼質(zhì)量管理平臺(tái)
2.如何使用Sonar Runner V2.3進(jìn)行代碼掃描
3.SonarQube代碼質(zhì)量管理平臺(tái)安裝與使用
4.http://deejay.iteye.com/blog/1901950
?
轉(zhuǎn)載于:https://www.cnblogs.com/fanbi/p/6504513.html
總結(jié)
以上是生活随笔為你收集整理的SonarQube代码质量管理工具安装与使用(sonarqube5.1.2 + sonar-runner-dist-2.4 + MySQL5.x)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 配置权限访问
- 下一篇: Javascript 思维导图 绘制基础