You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多模块Maven两步构建项目如何用sonar-maven-plugin单SonarQube项目分析?

解决Tycho多模块项目合并SonarQube分析的方法

针对你的Tycho项目(pom-first和manifest-first模块需分两次编译),可以通过分两次执行Sonar分析并利用增量缓存合并结果的方式,将两个profile的模块合并为单个SonarQube项目,具体步骤如下:

步骤1:编译profile1并生成Sonar分析缓存

执行编译+Sonar数据收集命令,指定本地缓存目录存储第一次分析的模块数据:

mvn clean install -Pprofile1 sonar:sonar \
  -Dsonar.projectKey=你的项目唯一标识Key \
  -Dsonar.projectName=你的项目显示名称 \
  -Dsonar.host.url=你的SonarQube服务器地址 \
  -Dsonar.login=你的SonarQube访问令牌 \
  -Dsonar.incremental=true \
  -Dsonar.incremental.analysis.cache.path=./sonar-local-cache

此步骤完成profile1模块的编译和Sonar分析,将分析数据缓存到本地./sonar-local-cache目录,不会直接提交到SonarQube服务器。

步骤2:编译profile2并合并缓存提交完整结果

执行第二次编译+Sonar分析命令,读取第一步的本地缓存,合并两个profile的模块数据后提交到SonarQube:

mvn clean install -Pprofile2 sonar:sonar \
  -Dsonar.projectKey=你的项目唯一标识Key \
  -Dsonar.projectName=你的项目显示名称 \
  -Dsonar.host.url=你的SonarQube服务器地址 \
  -Dsonar.login=你的SonarQube访问令牌 \
  -Dsonar.incremental=true \
  -Dsonar.incremental.analysis.cache.path=./sonar-local-cache

此步骤完成profile2模块的编译,同时加载第一步的缓存数据,将所有模块的分析结果合并后提交到SonarQube,形成一个完整的项目。

关键注意事项

  • 两次执行的sonar.projectKey必须完全相同,这是确保结果合并到同一SonarQube项目的核心。
  • 确保你的SonarQube服务器版本支持增量分析(SonarQube 6.7及以上版本均支持)。
  • 若使用较新版本的SonarQube,无需指定sonar.analysis.mode,仅需sonar.incremental=true即可开启增量分析模式。
  • 执行前需确保本地缓存目录./sonar-local-cache可读写,且两次执行使用同一目录。

内容的提问来源于stack exchange,提问作者Zlika

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 10:45:35