SonarQube(代碼質量管理)配置與使用


繼 Sonarqube(代碼質量管理)環境搭建,交大家如何配置與使用Sonarqube

1: 漢化Sonarqube:

  找到 Setting --> Update Center --> Available Plugins 

 漢化包安裝完成后,重啟Sonarqube后生效(重啟前順便把CheckStyle、PMD等插件也安裝好,避免重復重啟)

2: 重啟Sonarqube:

# /root/sonarqube/bin/linux-x86-64/sonar.sh restart

漢化完成后,刷新瀏覽器http://10.0.210.112:9090/sonarqube:

漢化成功(注意:漢化包並沒有完全漢化)

3: Myeclipse 中安裝Sonarqube 插件的安裝、配置、使用:

http://docs.sonarqube.org/display/SONAR/SonarQube+in+Eclipse

http://docs.sonarqube.org/display/SONAR/Installing+SonarQube+in+Eclipse

http://docs.sonarqube.org/display/SONAR/Configuring+SonarQube+in+Eclipse

http://docs.sonarqube.org/display/SONAR/Working+with+SonarQube+in+Eclipse

(參考官方文檔操作,不做講解,下面重點講解Sonarqube結合Maven插件的使用方法)

4: Maven分析器插件的配置與使用:

在Maven本地庫中的setting.xml配置文件中的<profiles></profiles> 節點中添加如下配置:

 <profiles>
    <profile>
      <id>sonar</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <!-- Example for MySQL-->
        <sonar.jdbc.url>
          jdbc:mysql://10.0.210.112:3306/sonarqube?useUnicode=true&amp;characterEncoding=utf8
        </sonar.jdbc.url>
        <sonar.jdbc.username>root</sonar.jdbc.username>
        <sonar.jdbc.password>wangfajun</sonar.jdbc.password>

        <!-- Optional URL to server. Default value is http://localhost:9000 -->
        <sonar.host.url>
          http://10.0.210.112:9090/sonarqube
        </sonar.host.url>
      </properties>
    </profile>
  </profiles>

使用Maven分析器進行分析,命令:

純Maven命令:mvn clean install sonar:sonar

Myeclipse中執行:clean install sonar:sonar

(如果你是第一次執行此命令,看執行日志你會發現它會先下載sonar-runner等插件)

成功執行完分析命令便可得到Web Server中查看代碼質量分析結果數據。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM