目录
使用 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分析结果