快速搭建sonar程式碼質量管理平臺
阿新 • • 發佈:2019-02-19
安裝
- 新增mysql驅動至\extensions\jdbc-driver\mysql\
- 建立mysql資料庫和使用者:10.22.10.139 db:sonar 使用者名稱/密碼:sonar/sonar
- 修改sonar.properties,註釋掉預設的資料庫配置,新增以下配置:
#----- MySQL 5.x # Comment the embedded database and uncomment the following line to use MySQL sonar.jdbc.url=jdbc:mysql://10.22.10.139:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
- 啟動bin/sonar.sh start
- 登陸http://localhost:9000/ 使用者名稱/密碼:admin/admin
使用maven分析專案:
- 在Maven的settings.xml(全域性配置檔案,不是專案的pom.xml)中新增以下配置:
<settings> <profiles> <profile> <id>sonar</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <!-- Example for MySQL--> <sonar.jdbc.url> jdbc:mysql://10.22.10.139:3306/sonar?useUnicode=true&characterEncoding=utf8 </sonar.jdbc.url> <sonar.jdbc.username>sonar</sonar.jdbc.username> <sonar.jdbc.password>sonar</sonar.jdbc.password> <!-- Optional URL to server. Default value is http://localhost:9000 --> <sonar.host.url> http://10.22.10.139:9000 </sonar.host.url> </properties> </profile> </profiles> </settings>
- 在pom.xml所在目錄執行maven命令:
mvn clean install
mvn sonar:sonar
使用Ecplise外掛:
- 安裝,外掛地址:http://dist.sonar-ide.codehaus.org/eclipse/
- 設定外掛引數,配置sonar伺服器地址:
- 將本地專案與sonar平臺關聯:
- 右鍵檢查程式碼質量: