快速搭建sonar代碼質量管理平臺

原文地址:http://blog.csdn.net/honglei915/article/details/38272435

安裝

  1. 下載,直接解壓http://www.sonarqube.org/downloads/
  2. 添加mysql驅動至\extensions\jdbc-driver\mysql\
  3. 創建mysql數據庫和用戶:10.22.10.139 db:sonar 用戶名/密碼:sonar/sonar
  4. 修改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
  5. 啓動bin/sonar.sh start
  6. 登陸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平臺關聯:


  • 右鍵檢查代碼質量:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章