Maven项目: 集成SonarQube进行代码审查

简介: Maven项目: 集成SonarQube进行代码审查

目录

使用 SonarQube 分析 Maven 项目

Maven 的 setting.xml文件

项目或模块的Pom文件

执行代码分析命令

Sonarqube分析结果



使用 SonarQube 分析 Maven 项目

Maven 的 setting.xml文件

我们需要配置 Maven 的 setting.xml文件,增加 sonarQube 配置。

<settings>
    <pluginGroups>
        <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
    </pluginGroups>
    <profiles>
        <profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- 配置 Sonar Host地址,默认:http://localhost:9000 -->
                <sonar.host.url>
                  http://192.168.172.128:9090
                </sonar.host.url>
            </properties>
        </profile>
     </profiles>
</settings>


项目或模块的Pom文件

<build>
    <pluginManagement>
        <!--使用 SonarQube 分析 Maven 项目-->
        <plugin>
            <groupId>org.sonarsource.scanner.maven</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>3.9.0.2155</version>
        </plugin>
        </plugins>
    </pluginManagement>
</build>


执行代码分析命令

mvn clean verify sonar:sonar -DskipTest=true

分析输出

[INFO] ------------- Run sensors on project
[INFO] Sensor Zero Coverage Sensor
[INFO] Sensor Zero Coverage Sensor (done) | time=205ms
[INFO] Sensor Java CPD Block Indexer
[INFO] Sensor Java CPD Block Indexer (done) | time=373ms
[INFO] SCM Publisher is disabled
[INFO] CPD Executor 183 files had no CPD blocks
[INFO] CPD Executor Calculating CPD for 510 files
[INFO] CPD Executor CPD calculation finished (done) | time=456ms
[INFO] Analysis report generated in 371ms, dir size=7 MB
[INFO] Analysis report compressed in 1480ms, zip size=2 MB
[INFO] Analysis report uploaded in 160ms
[INFO] ANALYSIS SUCCESSFUL, you can browse http://192.168.172.128:9090/dashboard?id=com.bigunion%3Abigunion
[INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[INFO] More about the report processing at http://192.168.172.128:9090/api/ce/task?id=AXmnaSyaTReHGmpr1jBO
[INFO] Analysis total time: 1:15.595 s
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for bigunion 2.3.0:
[INFO]
[INFO] bigunion ........................................... SUCCESS [01:17 min]
[INFO] bigunion-common .................................... SUCCESS [  0.020 s]
[INFO] bigunion-common-core ............................... SUCCESS [  3.103 s]
[INFO] bigunion-api ....................................... SUCCESS [  0.168 s]
[INFO] bigunion-api-system ................................ SUCCESS [  0.441 s]
[INFO] bigunion-common-redis .............................. SUCCESS [  0.362 s]
[INFO] bigunion-common-security ........................... SUCCESS [  0.423 s]
[INFO] bigunion-auth ...................................... SUCCESS [  3.714 s]
[INFO] bigunion-gateway ................................... SUCCESS [  1.622 s]
[INFO] bigunion-common-datascope .......................... SUCCESS [  0.351 s]
[INFO] bigunion-common-log ................................ SUCCESS [  0.340 s]
[INFO] bigunion-common-swagger ............................ SUCCESS [  0.253 s]
[INFO] bigunion-modules ................................... SUCCESS [  0.072 s]
[INFO] bigunion-system .................................... SUCCESS [  3.121 s]
[INFO] bigunion-file ...................................... SUCCESS [  2.189 s]
[INFO] bigunion-exam ...................................... SUCCESS [  4.003 s]
[INFO] bigunion-devicemag ................................. SUCCESS [  5.598 s]
[INFO] bigunion-student ................................... SUCCESS [  2.941 s]
[INFO] bigunion-project ................................... SUCCESS [  3.937 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:51 min
[INFO] Finished at: 2021-05-26T14:42:37+08:00
[INFO] ------------------------------------------------------------------------


Sonarqube分析结果

登录 http://192.168.172.128:9090/查看


目录
相关文章
|
1月前
|
Java Maven
手把手教你搭建Maven项目
手把手教你搭建Maven项目
31 0
|
2月前
|
Java Maven
java修改当前项目的maven仓库地址为国内
修改当前项目的maven仓库地址为国内
|
3月前
|
Dubbo Java 应用服务中间件
微服务框架(十)Maven Archetype制作Dubbo项目原型
  此系列文章将会描述Java框架Spring Boot、服务治理框架Dubbo、应用容器引擎Docker,及使用Spring Boot集成Dubbo、Mybatis等开源框架,其中穿插着Spring Boot中日志切面等技术的实现,然后通过gitlab-CI以持续集成为Docker镜像。   本文为Maven Archetype的制作及使用,使用archetype插件制作Dubbo项目原型
|
3月前
|
前端开发 Java Maven
IEAD MAVEN创建springboot 项目
IEAD MAVEN创建springboot 项目
29 0
|
29天前
|
Java Maven 开发工具
maven导入项目出现Unable to import maven project: See logs for details
maven导入项目出现Unable to import maven project: See logs for details
11 0
maven导入项目出现Unable to import maven project: See logs for details
|
1天前
|
Java Docker 容器
SpringBoot项目集成XXL-job
SpringBoot项目集成XXL-job
|
28天前
|
Java Maven
maven项目导出可执行jar
maven项目导出可执行jar
28 0
|
29天前
|
Java Maven
运行maven项目出现Error:java: JDK isn‘t specified for module ‘XXX‘
运行maven项目出现Error:java: JDK isn‘t specified for module ‘XXX‘
14 0
|
1月前
|
JavaScript Java 关系型数据库
实例!使用Idea创建SSM框架的Maven项目
实例!使用Idea创建SSM框架的Maven项目
38 0
|
1月前
|
XML Java 数据格式
springboot 微服务项目如何集成 html 页面
springboot 微服务项目如何集成 html 页面
29 0

推荐镜像

更多