持续集成篇_06_SonarQube代码质量管理平台的配置与使用

来源:互联网 发布:知乎招聘员工的 编辑:程序博客网 时间:2024/06/11 14:21

JDK1.7

一、SonarQube 的配置(前提,先用 admin 用户登录

 1、 安装中文汉化包:

 Setting >> Update Center >> Available Plugins >> LOCALIZATION >> Chinese Pack >> Install


安装完汉化包之后需要重启 SonarQube 才能生效(重启前可顺便把 CheckStyle、PMD 等插件安装一下)


[root@yxq ~]# /root/sonarqube/bin/linux-x86-64/sonar.sh restart
Stopping SonarQube...
Stopped SonarQube.
Starting SonarQube...
Started SonarQube.
[root@yxq ~]# 

重启完之后刷新 SonarQube

在cmd中执行sonar分析

mvn clean install sonar:sonar


Maven分析器插件的配置与使用

http://docs.sonarqube.org/display/SONAR/Installing+and+Configuring+Maven

 在 Maven 本地库中的 settings.xml

 <profiles></profiles>节点中添加如下配置: 


<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- Example for MySQL-->
<sonar.jdbc.url>
jdbc:mysql://192.168.1.51:3306/sonarqube?useUnicode=true&amp;characterEncoding=utf8
</sonar.jdbc.url>
<sonar.jdbc.username>root</sonar.jdbc.username>
<sonar.jdbc.password>123456</sonar.jdbc.password>
<!-- Optional URL to server. Default value is http://localhost:9000 -->
<sonar.host.url>
http://192.168.1.51:9090/sonarqube
</sonar.host.url>
</properties>
</profile>

启动sonarqube

[root@localhost ~]# /root/sonarqube/bin/linux-x86-64/sonar.sh start

在pom.xml中加入

<span style="white-space:pre"></span><build><pluginManagement><plugins><plugin><groupId>org.codehaus.sonar</groupId><artifactId>sonar-maven-plugin</artifactId><version>4.5.1</version></plugin></plugins></pluginManagement></build>
执行maven命令

clean install sonar:sonar

如果你是第一次运行此命令看执行日志你会发现它会先下载 sonar-runner 等插件


 

成功执行完分析命令后便可到 Web Server 中查看代码质量分析结果数据。



0 0
原创粉丝点击