SonarQube 代码质量管理平台的安装

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&amp;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 中查看代码质量分析结果数据。
相关文章
相关标签/搜索