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中查看代码质量分析结果数据。

 

posted @ 2016-03-18 14:33  君哥~  阅读(3020)  评论(0编辑  收藏  举报