Sonar入门(二): Maven集成Sonar

来源:互联网 发布:俄罗斯域名注册 编辑:程序博客网 时间:2024/06/08 09:27

Sonar对maven提供了简单可配的支持,要做的事情很简单——在maven/conf下settings.xml <profiles></profiles>标签之间添加如下内容:

  

    <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>sonar</sonar.jdbc.username>

        <sonar.jdbc.password>sonar</sonar.jdbc.password>

        <sonar.host.url>http://localhost:8384</sonar.host.url>

      </properties>

    </profile>

  

 

 

 

 

 

 

 

 

 

 

 

 




另外,在pom.xml文件中加入:

         <plugin><groupId>org.codehaus.mojo</groupId><artifactId>sonar-maven-plugin</artifactId><version>2.0</version></plugin>


这样maven已经集成了sonar。进入maven项目,执行mvn clean install,然后执行mvn sonar:sonar,就会执行静态代码检查(包括checkstyle、pmd)、覆盖率报告分析、代码行数统计,并插入到sonar依赖的数据库中。

以test为例:

a.        svn co https://svn.test.com/inf/computing/trunk/test

b.        cd ark && sh -ex build.sh# 执行编译测试

c.        cd arkproject && mvntest # 执行单元测试

d.        mvn sonar:sonar # 将执行静态代码检查+覆盖率分析+代码行数统计

 


原创粉丝点击