sonarqube使用mysql_SonarQube的安装、配置与使用
SonarQube是管理代碼質(zhì)量一個(gè)開放平臺(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后,解壓打開bin目錄,啟動(dòng)相應(yīng)OS目錄下的StartSonar。如本文演示使用的是win的64位系統(tǒng),則打開D:\sonar\sonarqube-5.3\sonarqube-5.3\bin\windows-x86-64\StartSonar.bat
2.啟動(dòng)瀏覽器,訪問(wèn)http://localhost:9000,如出現(xiàn)下圖則表示安裝成功。
二、配置篇
1.打開mysql,新建一個(gè)數(shù)據(jù)庫(kù)。
2.打開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-8sonar.login=admin
sonar.password=admin
url是數(shù)據(jù)庫(kù)連接地址,username是數(shù)據(jù)庫(kù)用戶名,jdbc.password是數(shù)據(jù)庫(kù)密碼,login是sonarqube的登錄名,sonar.password是sonarqube的密碼
4.重啟sonarqube服務(wù),再次訪問(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ù),再次訪問(wèn)http://localhost:9000/,即可看到中文界面
三、使用篇
1.打開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
3.配置環(huán)境變量
a.新建變量,name=SONAR_RUNNER_HOME。value=D:\sonar\sonar-scanner-2.5
b.打開path,輸入%SONAR_RUNNER_HOME%\bin;
c.sonar-runner -version,出現(xiàn)以下信息,則表示環(huán)境變量設(shè)置成功
4.打開要進(jìn)行代碼分析的項(xiàng)目根目錄,新建sonar-project.properties文件
5.輸入以下信息
# must be unique ina given SonarQube instance
sonar.projectKey=my:project
#this is the name displayed inthe SonarQube UI
sonar.projectName=apiautocore
sonar.projectVersion=1.0# Pathis 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 notset, SonarQube starts looking for source code fromthe directory containing
# the sonar-project.properties file.
sonar.sources=src
# Encoding of the source code. Defaultis defaultsystem 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.打開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)空指針異常,原因是我沒有進(jìn)行初始化就使用這個(gè)變量了。Over
預(yù)知更多使用,請(qǐng)登錄官網(wǎng)自行學(xué)習(xí)。
http://www.sonarqube.org/
http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Scanner
總結(jié)
以上是生活随笔為你收集整理的sonarqube使用mysql_SonarQube的安装、配置与使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python导入gif_Python之G
- 下一篇: 指标波动多大才算是异常?