天天看點

本地安裝SonarQube Community8.1社群版進行代碼品質管控

軟體環境

  Win7旗艦版64位,16G/4核I5

  需要使用JAVA11,本文選擇了adoptopenjdk,官網是:​​https://adoptopenjdk.net​​,筆者在最近了解到這個版本分支,

聽說他有一個基于IBM的OpenJ9的JVM,非常節省記憶體,适合記憶體消耗厲害的。HotSpot适合CPU計算密集型的;

按筆者對這裡SonarQube這款軟體的了解,應該是CPU使用的比較多,并不适合使用他,由于本地測試機器記憶體有限,

算是嘗鮮試用,其他JDK也可以,隻要版本是11就可以。

本地安裝SonarQube Community8.1社群版進行代碼品質管控

 不使用JDK11會報以下錯誤:

SonarQube requires Java 11 to run

本篇文章主旨,官方網站​​https://www.sonarqube.org/​​,因為其他版本需要費用,本文使用社群版 Community 8.1.0.31237 ,下載下傳位址:

​​https://www.sonarqube.org/downloads/​​

本地安裝SonarQube Community8.1社群版進行代碼品質管控

  PostgreSQL 10,SonarQube 7.9以後的版本已經放棄了MySQL,具體原因參考這個MySQL: SonarQube和Gitlab放棄支援的原因

資料庫和JDK是強制要求,必須使用JDK11和,不能使用Mysql,否則在啟動時會報以下錯誤:

mysql:Unsupported JDBC driver provider: mysql

   本文使用PostgreSQL 10,官方網站:​​https://www.postgresql.org​​,下載下傳位址:​​https://www.enterprisedb.com/downloads/postgres-postgresql-downloads​​

本地安裝SonarQube Community8.1社群版進行代碼品質管控

  安裝完成後進入資料庫目錄下面的pgAdmin 4,如圖所示:

本地安裝SonarQube Community8.1社群版進行代碼品質管控

 點選pgAdmin啟動web程式,進來會預設設定密碼,随便設定一個并且記錄下來。

 然後右鍵Login/Group Roles彈出以下圖檔

 按照以下圖示操作:

本地安裝SonarQube Community8.1社群版進行代碼品質管控
本地安裝SonarQube Community8.1社群版進行代碼品質管控
本地安裝SonarQube Community8.1社群版進行代碼品質管控

 建立資料庫

本地安裝SonarQube Community8.1社群版進行代碼品質管控

 配置資料庫權限

本地安裝SonarQube Community8.1社群版進行代碼品質管控

本文使用的語言包版本:8.1-RC1

下載下傳位址:​​https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases/tag/sonar-l10n-zh-plugin-8.1-RC1​​,

本地安裝SonarQube Community8.1社群版進行代碼品質管控

至此,以上軟體環境準備完畢

配置環境

 打開sonarQube目錄下的sonar.properties,添加以下參數

打開warpper.conf修改屬性為如下配置

上面的D:\develop\AdoptOpenJDK\jdk-11.0.5.10-openj9\是我本地JDK11的安裝路徑

啟動前需要下載下傳postgresql的驅動下載下傳回來,并且要把上面的語言包放到SonarQube的目錄中

驅動檔案​​PostgreSQL JDBC 4.2 Driver, 42.2.9​​

本地安裝SonarQube Community8.1社群版進行代碼品質管控

JDBC安裝目錄

本地安裝SonarQube Community8.1社群版進行代碼品質管控

将下載下傳回來的語言包sonar-l10n-zh-plugin-8.1-RC1.jar放入extensions\plugins目錄中

本地安裝SonarQube Community8.1社群版進行代碼品質管控

切入到bin\windows-x86-64目錄,運作StartSonar.bat 運作成功以後界面如下

本地安裝SonarQube Community8.1社群版進行代碼品質管控
本地安裝SonarQube Community8.1社群版進行代碼品質管控

中途如果遇到其他問題,自己檢視日志解決吧,筆者先下載下傳開發者版本,然後啟動,占用了9001端口,沒啟動成功

使用以下方法查找到對應程序id并且殺死

windows下根據tcp端口查詢對應的程序id(端口被占用)

因為wrapper.exe會把程式設定為守護程序,光殺死了9000端口,沒把另外一個9001端口對應程序關閉。

如果你想把他設定為服務,可以這樣做:

安裝服務 bin/InstallNTService.bat   解除安裝服務 bin/UninstallNTService.bat

啟動服務 bin/StartNTService.bat    停止服務bin/StopNTService.bat

使用起來非常簡單

本地安裝SonarQube Community8.1社群版進行代碼品質管控

安裝好以後打開網址http://localhost:9000,初次啟動背景會下載下傳插件進行初始化

本地安裝SonarQube Community8.1社群版進行代碼品質管控

預設登入使用者名及密碼為admin/admin

本地安裝SonarQube Community8.1社群版進行代碼品質管控

插件

插件是一個衡量軟體是否有擴充性,以及能否保證持續生命力的一種元件技術。進入背景,按照圖示打開插件市場

本地安裝SonarQube Community8.1社群版進行代碼品質管控

 界面如下

本地安裝SonarQube Community8.1社群版進行代碼品質管控

各位看官可以在此自己選擇的插件:比如

Checkstyle 

Findbugs

MyBatis Plugin for SonarQube

YAML Analyzer

Code Smells

 下一篇文章将介紹如何使用:IDEA中使用插件sonarlint連接配接到SonarQube對代碼品質進行管控