使用sonar
用來做前端代碼QC丛楚,看網(wǎng)上很多都下載了安裝mysql劲腿,我搭建過程中沒有安裝mysql,
安裝Sonar (https://www.sonarqube.org/downloads/)
最新版是8.4,后發(fā)現(xiàn)啟動(dòng)不起來,后面改為7.4,滑動(dòng)頁面底部選擇需要的版本
硫兰。
image.png
解壓后放在
/usr/local
目錄下面诅愚。
- ./sonar.sh start 啟動(dòng)服務(wù)
- ./sonar.sh stop 停止服務(wù)
- ./sonar.sh restart 重啟服務(wù)
啟動(dòng)再訪問http://localhost:9000/
即可啟動(dòng)sonar,默認(rèn)賬號(hào)/密碼都是admin
,進(jìn)行登錄劫映。
漢化 (https://github.com/SonarQubeCommunity/sonar-l10n-zh)
漢化插件默認(rèn)支持的版本是最新版本
image.png
由于我的sonar不是最新版本违孝,需要手動(dòng)安裝插件。(漢化有兼容的漢化包)
- git clone https://github.com/SonarQubeCommunity/sonar-l10n-zh
- cd sonar-l10n-zh/
- git checkout sonar-l10n-zh-plugin-1.24
-
mvn package
image.png
最后的命令mvn是通過maven生成將當(dāng)前文件打包成jar包泳赋,需要先JDK雌桑。
maven下載(http://maven.apache.org/download.cgi) mvn -v
查看maven是否安裝成功。
image.png
添加環(huán)境變量 (open ~/.bash_profile)
export MAVEN_HOME=/Users/liuyong/maven/apache-maven-3.6.3 export PATH=$PATH:$MAVEN_HOME/bin
通過
mvn package
命令生成target/sonar-l10n-zh-plugin-1.24.jar
文件祖今。將jar文件復(fù)制到
/usr/local/sonarqube-7.4/extensions/plugins
重啟sonar就已經(jīng)漢化成功校坑。
sonarscanner安裝(https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/)
添加環(huán)境變量
export PATH=$PATH:/usr/local/sonar-scanner-4.1.0.1829-macosx/bin
更新base_profile 文件 source ~/.bash_profile
很多文章需要在項(xiàng)目的根目錄先創(chuàng)建sonar-project.properties
再上傳 拣技,我這邊試用了可以不用創(chuàng)建此文件。
-
sonar上創(chuàng)建項(xiàng)目
image.png -
創(chuàng)建令牌
image.png -
選擇分析的項(xiàng)目和系統(tǒng) 創(chuàng)建任務(wù)標(biāo)識(shí)
image.png -
復(fù)制命令
image.png
在項(xiàng)目的根目錄下執(zhí)行上面的文件耍目,會(huì)自動(dòng)將需要分析的項(xiàng)目上傳到sonar進(jìn)行分析
image.png