SonarQube安裝、配置與使用教程圖解
SonarQube是管理代碼質(zhì)量一個(gè)開(kāi)放平臺(tái),可以快速的定位代碼中潛在的或者明顯的錯(cuò)誤,下面將會(huì)介紹一下這個(gè)工具的安裝、配置以及使用。
準(zhǔn)備工作;
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數(shù)據(jù)庫(kù)(不再介紹)
一、安裝篇
1.下載好sonarqube后,解壓打開(kāi)bin目錄,啟動(dòng)相應(yīng)OS目錄下的StartSonar。如本文演示使用的是win的64位系統(tǒng),則打開(kāi)D:\sonar\sonarqube-5.3\sonarqube-5.3\bin\windows-x86-64\StartSonar.bat
2.啟動(dòng)瀏覽器,訪(fǎng)問(wèn)http://localhost:9000,如出現(xiàn)下圖則表示安裝成功。
二、配置篇
1.打開(kāi)mysql,新建一個(gè)數(shù)據(jù)庫(kù)。
2.打開(kāi)sonarqube安裝目錄下的D:\sonar\sonarqube-5.3\sonarqube-5.3\conf\sonar.properties文件
3.在mysql5.X節(jié)點(diǎn)下輸入以下信息
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
sonar.sorceEncoding=UTF-8
sonar.login=admin
sonar.password=admin
url是數(shù)據(jù)庫(kù)連接地址,username是數(shù)據(jù)庫(kù)用戶(hù)名,jdbc.password是數(shù)據(jù)庫(kù)密碼,login是sonarqube的登錄名,sonar.password是sonarqube的密碼
4.重啟sonarqube服務(wù),再次訪(fǎng)問(wèn)http://localhost:9000,會(huì)稍微有點(diǎn)慢,因?yàn)橐跏蓟瘮?shù)據(jù)庫(kù)信息
5.數(shù)據(jù)庫(kù)初始化成功后,登錄
6.按照下圖的點(diǎn)擊順序,進(jìn)入插件安裝頁(yè)面
7.搜索chinese Pack,安裝中文語(yǔ)言包
8.安裝成功后,重啟sonarqube服務(wù),再次訪(fǎng)問(wèn)http://localhost:9000/,即可看到中文界面
三、使用篇
1.打開(kāi)D:\sonar\sonar-scanner-2.5\conf\sonar-runner.properties文件
2.mysql節(jié)點(diǎn)下輸入以下信息
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
注意:如果測(cè)試項(xiàng)目與服務(wù)器不在同一臺(tái)機(jī)子,則需要添加服務(wù)器的IP:
#----- Default SonarQube server
sonar.host.url=http://XXX.XXX.XXX.XXX:9000[/code]
3.配置環(huán)境變量
a.新建變量,name=SONAR_RUNNER_HOME。value=D:\sonar\sonar-scanner-2.5
b.打開(kāi)path,輸入%SONAR_RUNNER_HOME%\bin;
c.sonar-runner -version,出現(xiàn)以下信息,則表示環(huán)境變量設(shè)置成功
4.打開(kāi)要進(jìn)行代碼分析的項(xiàng)目根目錄,新建sonar-project.properties文件
5.輸入以下信息
# 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是項(xiàng)目名字,sources是源文件所在的目錄
6.設(shè)置成功后,啟動(dòng)sonarqube服務(wù),并啟動(dòng)cmd
7.在cmd進(jìn)入項(xiàng)目所在的根目錄,輸入命令:sonar-runner,分析成功后會(huì)出現(xiàn)下圖
8.打開(kāi)http://localhost:9000/,我們會(huì)看到主頁(yè)出現(xiàn)了分析項(xiàng)目的概要圖
9.我們點(diǎn)擊項(xiàng)目,選擇問(wèn)題鏈接,會(huì)看到分析代碼的bug,哇,好多
10.選擇一個(gè)最嚴(yán)重的bug,看看
原來(lái)是這個(gè)地方會(huì)出現(xiàn)空指針異常,原因是我沒(méi)有進(jìn)行初始化就使用這個(gè)變量了。Over
預(yù)知更多使用,請(qǐng)登錄官網(wǎng)自行學(xué)習(xí)。
http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Scanner
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
SpringMVC中的ResourceUrlProviderExposingInterceptor詳解
這篇文章主要介紹了SpringMVC中的ResourceUrlProviderExposingInterceptor詳解,ResourceUrlProviderExposingInterceptor是Spring MVC的一個(gè)HandlerInterceptor,用于向請(qǐng)求添加一個(gè)屬性,需要的朋友可以參考下2023-12-12springboot實(shí)現(xiàn)以代碼的方式配置sharding-jdbc水平分表
這篇文章主要介紹了springboot實(shí)現(xiàn)以代碼的方式配置sharding-jdbc水平分表,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-11-11SpringBoot整合MyBatis-Plus3.1教程詳解
這篇文章主要介紹了SpringBoot整合MyBatis-Plus3.1詳細(xì)教程,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08Java char[]數(shù)組轉(zhuǎn)成String類(lèi)型詳細(xì)介紹
這篇文章詳細(xì)介紹了Java char[]數(shù)組轉(zhuǎn)成String類(lèi)型(char to String)的方法,文章中有詳細(xì)的代碼示例,需要的朋友可以參考閱讀2023-04-04親測(cè)解決,nacos下線(xiàn)失敗問(wèn)題
這篇文章主要介紹了親測(cè)解決,nacos下線(xiàn)失敗問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07