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

Maven release:perform执行失败:无法从SCM检出问题排查

问题

使用Maven 3.9 + Java Spring Boot 3.1.1,搭配Bitbucket和Git做版本发布管理,pom.xml中的SCM配置如下:

<scm>
    <connection>scm:git:git://ssh@bitbucket.org/travellinckcorpdevelopers/notification-service.git</connection>
    <developerConnection>scm:git:ssh://git@bitbucket.org/travellinckcorpdevelopers/notification-service.git</developerConnection>
    <url>https://bitbucket.org/travellinckcorpdevelopers/notification-service</url>
</scm>

执行mvn -B release:prepare能正常递增project.version,但执行mvn -B release:perform提交更新后的pom到Git时,报错:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:3.1.1:perform (default-cli) on project notification-service: Unable to checkout from SCM
[ERROR] Provider message:
[ERROR] The git-clone command failed.
[ERROR] Command output:
[ERROR] Cloning into 'checkout'...
[ERROR] ssh: Could not resolve hostname bitbucket.org:travellinckcorpdevelopers: Name or service not known
[ERROR] fatal: Could not read from remote repository.
[ERROR] 
[ERROR] Please make sure you have the correct access rights
[ERROR] and the repository exists.

通过ssh -T git@bitbucket.org测试返回authenticated via ssh key.,SSH密钥认证正常。请问是SCM连接配置错误还是公钥用户缺少权限?该如何解决?

原因分析

这是SCM连接配置错误导致的,和权限无关。错误日志里的bitbucket.org:travellinckcorpdevelopers是解析失败的主机名,说明Maven在解析SCM URL时把仓库路径的一部分当成了主机名的后缀,根源是connection字段的URL格式错误:

  • git://协议不需要指定SSH用户名,你错误地写成了git://ssh@,这种格式会让Git解析时把ssh@bitbucket.org之后的/travellinckcorpdevelopers错误拼接成主机名的一部分,最终导致解析失败。
  • developerConnection的格式是对的,但connection的错误会影响release插件的checkout流程。

解决步骤

  1. 修正pom.xml中的SCM connection配置
    将connection字段的协议和用户名修正为正确格式,Bitbucket的Git只读连接可以用HTTPS格式,或者保持SSH格式但去掉错误的用户名前缀:

    <scm>
        <!-- 方案1:用HTTPS只读连接(推荐) -->
        <connection>scm:git:https://bitbucket.org/travellinckcorpdevelopers/notification-service.git</connection>
        <!-- 方案2:用SSH格式(和developerConnection保持一致) -->
        <!-- <connection>scm:git:ssh://git@bitbucket.org/travellinckcorpdevelopers/notification-service.git</connection> -->
        <developerConnection>scm:git:ssh://git@bitbucket.org/travellinckcorpdevelopers/notification-service.git</developerConnection>
        <url>https://bitbucket.org/travellinckcorpdevelopers/notification-service</url>
    </scm>
    
  2. 清理release插件临时文件
    执行失败后插件会生成checkout临时目录,先删除该目录避免残留影响:

    rm -rf checkout
    
  3. 重新执行发布流程
    先回滚之前的prepare操作(如果需要),再重新执行发布:

    mvn release:rollback
    mvn -B release:prepare
    mvn -B release:perform
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 11:53:24