Sonar快速入门

简介

转自oschina的介绍(http://www.oschina.net/p/sonar/)

 

Sonar (SonarQube)是一个开源平台,用于管理源代码的质量。Sonar 不只是一个质量数据报告工具,更是代码质量管理平台。支持的语言包括:JavaPHPC#CCobolPL/SQLFlex 等。

主要特点:

· 代码覆盖:通过单元测试,将会显示哪行代码被选中

· 改善编码规则

· 搜寻编码规则:按照名字,插件,激活级别和类别进行查询

· 项目搜寻:按照项目的名字进行查询

· 对比数据:比较同一张表中的任何测量的趋势

架构图:

 

下载与安装

下载地址:http://www.sonarqube.org/downloads/

我下载的是:sonar-3.7.3.zip

 

解压(D:\install\sonar-3.7.3

 

进入解压缩目录,修改conf/sonar.properties文件,配置数据库连接

1
2
3
4
5
6
7
8
9
10
11
12
......
# Permissions to create tables and indexes must be granted to JDBC user.
# The schema must be created first.
#sonar.jdbc.username:                       sonar
#sonar.jdbc.password:                       sonar
.......
#----- MySQL 5.x
# Comment the embedded database and uncomment the following line to use MySQL
sonar.jdbc.username:                       root
sonar.jdbc.password:                       123
......

 

红色标注的是默认打开的,为了统一管理,我把它给注释掉了,

 

灰色背景的是新添加的,因为我使用的数据库是mysql

 

binD:\install\sonar-3.7.3\bin)目录下有各种操作系统的可执行文件,我本地的操作系统是XP,所以进入D:\install\sonar-3.7.3\bin\windows-x86-32执行StartSonar.bat即可完成启动。

 

访问:http://localhost:9000/

如果能访问说明成功了

 

 

配置maven

修改maven的配置文件E:\maven\apache-maven-3.1.1\conf\settings.xml,在profiles下添加以下代码

1
2
3
4
5
6
7
8
9
10
11
12
13
< profile >
     < id >sonar</ id >
     < activation >
         < activeByDefault >true</ activeByDefault >
     </ activation >
     < properties >
         < sonar.jdbc.url >jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8</ sonar.jdbc.url >
         < sonar.jdbc.driver >com.mysql.jdbc.Driver</ sonar.jdbc.driver >
         < sonar.jdbc.username >root</ sonar.jdbc.username >
         < sonar.jdbc.password >123</ sonar.jdbc.password >
         < sonar.host.url >http://localhost:9000</ sonar.host.url >
     </ properties >
</ profile >

 

注:如果不配置,会出现连接不了数据库的异常

 

在项目里加下以下插件:

1
2
3
4
5
< plugin >
    < groupId >org.codehaus.mojo</ groupId >
    < artifactId >sonar-maven-plugin</ artifactId >
    < version >2.2</ version >
</ plugin >

 

运行sonar测试

E:\git\656463>cd 656463-cms

 

E:\git\656463\656463-cms>mvn sonar:sonar

 

好了,直接访问http://localhost:9000/即可看到测试结果了

 

原文链接:http://www.656463.com/article/2442

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值