Windows下maven-sonarqube集成

1.SonarQube简单介绍

SonarQube能够提供对代码的一整套检查扫描和分析功能,拥有一套服务器端程序,然后再通过客户端或者别的软件的插件的形式完成对各开发环境和软件的支持。

2.安装sonar的前提必须先安装jdk、maven,这里省略jdk\maven的安装步骤

3.下载SonarQube https://www.sonarqube.org/downloads/

4.解压并放置在任意文件夹下,I:\sonarqube-6.7.5

Windows下maven-sonarqube集成

5.配置sonar

5.1修改I:\sonarqube-6.7.5\conf配置文件

添加jdbc相关配置如下:

sonar.jdbc.username=root
sonar.jdbc.password=root
sonar.sorceEncoding=UTF-8

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
以及SCM配置为true
sonar.scm.disabled=true

5.2创建MySQL名为sonar的数据库

Windows下maven-sonarqube集成

6.启动

双击I:\sonarqube-6.7.5\bin\windows-x86-64下的StartSonar.bat

注意:

SonarQube server默认使用的是9000端口,如果目前9000端口已经占用,打开sonar.properties文件进行更改端口的设置

打开浏览器进入http://localhost:9000,将会显示界面

7.集成maven

修改maven的配置文件setting

    <profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- Optional URL to server. Default value is http://localhost:9000-->
                <sonar.host.url>
                  http://localhost:9000
                </sonar.host.url>
                <sonar.scm.disabled>true</sonar.scm.disabled>
            </properties>
        </profile>

8.重启sonar服务,进入项目根目录,执行:mvn clean verify sonar:sonar,编译通过
打开界面如下:

Windows下maven-sonarqube集成