Sonar 安装手册

前言

公司前段时间推动项目代码质量评估,发现Sonar不错,能够集成checkstyle,findbugs,pmd的大部分功能。

Sonar支持三种运行方式: Maven集成,Ant集成,Sonar Runner。

下载

到官方网站下载Sonar的压缩包,解压到任意目录

创建数据库 

Sonar默认使用嵌入式Derby数据库,如果要迁移到Mysql上,需首先创建一个sonar/sonar的UTF-8的mysql数据库,并授权访问sonar库
mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> grant all privileges on sonar.\* to 'sonar'@'localhost' identified by 'sonar';
mysql> flush privileges;

修改$SONAR_HOME/conf/sonar.properties文件:

Properties代码:
#sonar.jdbc.url: jdbc:derby://localhost:1527/sonar;create=true
#sonar.jdbc.driver: org.apache.derby.jdbc.ClientDriver
#sonar.jdbc.defaultTransactionIsolation: 1
#sonar.jdbc.validationQuery: values(1)
sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.driver: com.mysql.jdbc.Driver
sonar.jdbc.validationQuery: select 1

配置maven2 

编辑位于$MAVEN_HOME/conf 下的settings.xml文件 

<profile>  
    <id>sonar</id>  
    <activation>  
        <activeByDefault>true</activeByDefault>  
    </activation>  
    <properties>  
        <sonar.jdbc.url>  
            jdbc:mysql://localhost:3306/sonar?useUnicode=true
        </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:9000</sonar.host.url>  
    </properties>  
</profile>

启动sonar 

执行位于以下脚本
$SONAR_HOME/bin/$OS_VERSION/**

在maven工程下运行mvn sonar:sonar

原文地址:https://www.cnblogs.com/biglaojiang/p/3080243.html