原文地址:http://blog.csdn.net/honglei915/article/details/38272435
安裝
- 下載,直接解壓http://www.sonarqube.org/downloads/
- 添加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平臺關聯:
- 右鍵檢查代碼質量: