sonar使用

代码质量检查工具 sonar

1. 下载,版本sonar 4.5.1

运行bin下的bat文件,浏览器中访问: http://localhost:9000 , 成功。

2. 修改数据库为mysql数据库

先在mysql中新建数据库sonar,用户sonar,远程访问ok后,编辑sonarqube-4.5.1\conf\sonar.properties, 如下:

sonar.jdbc.username=sonar
sonar.jdbc.password=sonar

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

3.汉化:

访问 http://docs.sonarqube.org/display/SONAR/Plugin+Library  ,找到Localization ,也就是http://docs.codehaus.org/display/SONAR/Localization

,下载到sonarqube-4.5.1\extensions\plugins目录下,重启sonar。

 

4. 修改maven安装目录下conf/setting.xml文件,添加

 
    <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.driverClassName>com.mysql.jdbc.Driver</sonar.jdbc.driverClassName>
             <sonar.jdbc.username>sonar</sonar.jdbc.username>
             <sonar.jdbc.password>sonar</sonar.jdbc.password>
             <sonar.host.url>http://localhost:9000</sonar.host.url>
         </properties>
  </profile>

注: 我没有修改maven项目的pom.xml 。。。

 5. 命令行运行

mvn clean install

mvn sonar:sonar

(注:装了插件,直接ctrl+M呼出命令行到文件目录),

然后等待Build success .

此时在http://localhost:9000就可以看到结果报告了,感觉还不错

 

posted @ 2015-01-15 11:53  知行合1  阅读(749)  评论(0编辑  收藏  举报