系统持续集成-SonarQube+Maven 分析器插件的配置与使用

安装完成SonarQube之后,我们的系统中是没有项目的。


这里写图片描述

那么接下来我们来使用SonarQube+Maven 分析器插件来使用SonarQube分析我们的代码。

1、Maven配置

在 Maven 本地库中的 settings.xml 配置文件中的节点中添加如下配置:

<profile>
    <id>sonar</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
    <!-- Example for MySQL-->
        <sonar.jdbc.url>jdbc:mysql://192.168.199.252:3306/tfssonar?useUnicode=true&amp;characterEncoding=utf8</sonar.jdbc.url>
        <sonar.jdbc.username>root</sonar.jdbc.username>
        <sonar.jdbc.password>654321</sonar.jdbc.password>
        <sonar.host.url>http://192.168.199.246:9000/sonar</sonar.host.url>
    </properties>
</profile>

2、使用 Maven 分析器进行分析

使用 Maven 分析器进行代码分析有两种方式,一种是直接执行纯Maven 命令。

mvn clean install sonar:sonar

我们以一个实例的形式来演示通过Maven命令如何执行代码分析。
首先进入Maven项目pom.xml文件所在的目录


这里写图片描述
这里写图片描述

等待项目构建完成之后,我们进入SonarQube平台我们就可以看到当前构建的项目的代码的一些信息如下。

这里写图片描述

在Eclipse中执行如下命令进行分析

clean install sonar:sonar


这里写图片描述

点击运行(Run)我们可以看到如下信息


这里写图片描述

等待项目构建完成之后,我们进入SonarQube平台我们就可以看到当前构建的项目的代码的一些信息如下。

这里写图片描述

猜你喜欢

转载自blog.csdn.net/zyhlwzy/article/details/80338300