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

Google Cloud Shell无法获取spring-cloud-gcp-starter-secretmanager的Maven依赖

解决Spring Cloud GCP Secret Manager依赖无法解析的问题

问题根源

  1. GroupID错误:Spring Cloud GCP 3.x及以上版本的GroupID已从org.springframework.cloud变更为com.google.cloud,你使用的旧GroupID无法找到对应版本的依赖。
  2. 版本兼容性问题:Spring Cloud GCP版本需要与Spring Boot版本匹配,若你的Spring Boot是3.x版本,3.4.0版本的Spring Cloud GCP并不兼容,需使用4.x版本。

解决步骤

1. 修正依赖的GroupID并使用BOM管理版本

在pom.xml中添加Spring Cloud GCP的依赖管理BOM,避免手动指定版本带来的兼容性问题:

<dependencyManagement>
    <dependencies>
        <!-- Spring Cloud GCP 依赖管理 BOM -->
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>spring-cloud-gcp-dependencies</artifactId>
            <version>3.4.0</version> <!-- 若Spring Boot是2.7.x用此版本;若为3.x则用4.4.0 -->
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

然后修改Secret Manager依赖,去掉手动指定的版本,使用BOM中的版本:

<dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>spring-cloud-gcp-starter-secretmanager</artifactId>
</dependency>

2. 确认Spring Boot版本兼容性

  • 若你的Spring Boot版本是2.7.x,使用Spring Cloud GCP 3.4.0是兼容的。
  • 若你的Spring Boot版本是3.x,需将BOM版本改为4.4.0,确保版本匹配。

3. 刷新Maven依赖

在Google Cloud Shell中执行以下命令,强制刷新依赖:

mvn clean install -U

验证依赖是否正常

执行mvn dependency:tree命令,检查输出中是否存在com.google.cloud:spring-cloud-gcp-starter-secretmanager,确认依赖已成功解析。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 03:21:36