一、maven 全局配置
<settings>
<pluginGroups>
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- Optional URL to server. Default value is http://localhost:9000 -->
<sonar.host.url>
http://myserver:9000
</sonar.host.url>
</properties>
</profile>
</profiles>
</settings>
- 使用特定版本 scanner maven 插件
mvn sonar:sonar
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:LATEST:sonar
- 代码分析基本命令
#编译后直接分析
mvn clean compile sonar:sonar
#执行单元测试后分析,用于收集单元测试与单测覆盖率
mvn clean test sonar:sonar
#执行集成测试后分析,用于收集集成测试与集成测试覆盖率
mvn clean verify sonar:sonar
- 环境变量的配置
export SONAR_HOME=/Users/jd/soft/sonar-scanner-6.2.1.4610
export PATH=$PATH:$SONAR_HOME/bin
export SQ_HOST=http://127.0.0.1:9000/
export SQ_TOKEN=squ_dbb1913e095a92a727a918a9ba6b1af94b007748
- maven 单模块项目代码分析
cd maven-basic
mvn clean verify \
org.sonarsource.scanner.maven:sonar-maven-plugin:LATEST:sonar \
-Dsonar.host.url=$SQ_HOST \
-Dsonar.login=$SQ_TOKEN
- maven 多模块项目代码分析
cd maven-multimodule
mvn clean verify \
org.sonarsource.scanner.maven:sonar-maven-plugin:LATEST:sonar \
-Dsonar.host.url=$SQ_HOST \
-Dsonar.login=$SQ_TOKEN
- sonarqube 多语言代码分析
cd maven-multilingual
mvn clean verify \
org.sonarsource.scanner.maven:sonar-maven-plugin:LATEST:sonar \
-Dsonar.host.url=$SQ_HOST \
-Dsonar.login=$SQ_TOKEN
- 项目代码分析
mvn clean compile \
org.sonarsource.scanner.maven:sonar-maven-plugin:LATEST:sonar \
-Dsonar.host.url=$SQ_HOST \
-Dsonar.login=$SQ_TOKEN
start.spring.io
sonar-scanning-examples地址
SonarScanner for Maven官网地址