1、建立 sonarqube 數據庫(UTF-8 編碼) 2、安裝 SonarQube 的 Web Server 下載最新 LTS 版的 SonarQube 安裝包(當前版本爲 sonarqube-4.5.4.zip): 下載地址:http://www.sonarqube.org/downloads/ 下載: # wget http://dist.sonar.codehaus.org/sonarqube-4.5.4.zip 解壓安裝: #unzip sonarqube-4.5.4.zip #mv sonarqube-4.5.4 sonarqube 編輯 sonar 配置: #cd sonarqube/conf/ #vi sonar.properties sonar.jdbc.username=root sonar.jdbc.password=root #----- MySQL 5.x sonar.jdbc.url=jdbc:mysql://localhost:3306/sonarqube?useUnicode=true&characterE ncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance sonar.web.host=0.0.0.0 sonar.web.context=/sonarqube sonar.web.port=9090 保存以上配置(注意,要看看默認的 9000 端口是否已被佔用) 防火牆中打開 9090 端口: # vi /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 9090 -j ACCEPT 重啓防火牆,使端口配置生效 # service iptables restart 啓動 SonarQube Web Server # /root/sonarqube/bin/linux-x86-64/sonar.sh start (初次啓動會自動建表和作相應的初始化) 瀏覽器中輸入:http://192.168.4.221:9090/sonarqube/
Maven 分析器插件的配置與使用 http://docs.sonarqube.org/display/SONAR/Installing+and+Configuring+Maven 在 Maven 本地庫中的 settings.xml(我這裏是 settings_ssm.xml)配置文件中的 <profiles></profiles>節點中添加以下配置: <profile> <id>sonar</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <!-- Example for MySQL--> <sonar.jdbc.url> jdbc:mysql://192.168.4.221:3306/sonarqube?useUnicode=true&chara cterEncoding=utf8 </sonar.jdbc.url> <sonar.jdbc.username>root</sonar.jdbc.username> <sonar.jdbc.password>root</sonar.jdbc.password> <!-- Optional URL to server. Default value is http://localhost:9000 --> <sonar.host.url> http://192.168.4.221:9090/sonarqube </sonar.host.url> </properties> </profile>
使用 Maven 分析器進行分析,命令: 純 Maven 命令: mvn clean install sonar:sonar MyEclipse 中執行: clean install sonar:sonar (若是你是第一次運行此命令,看執行日誌你會發現它會先下載 sonar-runner 等插件) 成功執行完分析命令後即可到 Web Server 中查看代碼質量分析結果數據。