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

Maven执行sonar:sonar报错求助:组件加载/连接失败

两类SonarQube Maven扫描错误排查方案

第二类错误:SonarQube服务器连接拒绝

错误信息:

Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project project-name : Unable to execute SonarQube: Fail to get bootstrap index from server: Failed to connect to localhost/0:0:0:0:0:0:0:1:9000: Connection refused

排查与解决:

  • 确认SonarQube服务状态:执行ps aux | grep sonar(Linux)或查看系统服务列表,确保SonarQube进程正在运行。若服务未启动,手动启动SonarQube。
  • 检查端口占用与配置:
    • 查看SonarQube配置文件sonar.properties中的sonar.web.port,确认监听端口是否为9000(或自定义端口)。
    • 用netstat -tulpn | grep <端口号>检查端口是否被其他进程占用,若被占用则更换SonarQube端口或停止占用进程。
  • 指定正确的SonarQube地址:如果SonarQube不在本地运行,或端口已修改,执行扫描时添加服务器地址参数:
    mvn sonar:sonar -Dsonar.host.url=http://<sonar-server-ip>:<port>
    
  • 排查网络/防火墙限制:确保Jenkins所在服务器能访问SonarQube服务器的目标端口,无防火墙规则或安全组拦截。

第一类错误:协议消息标签不匹配

错误日志核心:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project maven-web-application: Unable to load component class org.sonar.scanner.bootstrap.ScannerPluginInstaller: Unable to load component class org.sonar.scanner.bootstrap.PluginFiles: Unable to load component class org.sonar.scanner.bootstrap.GlobalConfiguration: Unable to load component class org.sonar.scanner.bootstrap.GlobalServerSettings: Unable to load settings: Protocol message end-group tag did not match expected tag.

排查与解决:

  • 匹配SonarQube与Maven扫描器版本:你使用的SonarQube是7.6.0,需确保sonar-maven-plugin版本与之兼容。SonarQube 7.6.0推荐的插件版本范围是3.7.x~3.9.x,若当前版本存在兼容性问题,可尝试切换到3.7.0.1746或官方推荐的对应版本(在POM或Maven settings中指定版本)。
  • 清理Sonar缓存:删除Jenkins用户下的Sonar缓存目录/var/lib/jenkins/.sonar/cache,缓存损坏可能导致通信协议解析错误,清理后重新执行扫描命令。
  • 确认JDK配置:SonarQube服务需运行在JDK11,但Maven构建项目用JDK8完全兼容,无需修改项目POM的Java版本。只需保证SonarQube服务本身的运行环境是JDK11即可。
  • 检查Maven Sonar配置:确认settings.xml中SonarQube的认证信息(如token)、服务器地址等配置无误,错误的配置可能导致通信异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 13:01:25