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

为何Maven从私有GitHub仓库查找Spring Boot依赖?如何解决?

问题解决方案

错误根源

Maven尝试从你的私有GitHub仓库拉取Spring Boot官方父依赖,该私有仓库需要认证(导致401未授权错误),但官方依赖本应从Maven中央仓库获取。同时,Maven缓存了这次失败请求,默认不会自动重试。

解决步骤

1. 清理本地缓存的失败记录

找到本地Maven仓库中对应Spring Boot父依赖的目录并删除,清除缓存的失败状态:

  • 路径示例:~/.m2/repository/org/springframework/boot/spring-boot-starter-parent/2.5.0
  • 也可执行命令强制更新依赖:
    mvn clean install -U
    

2. 修改pom.xml的仓库配置

确保中央仓库优先拉取公共依赖,同时限制私有仓库仅处理你的自定义依赖(org.csystem组):

<repositories>
    <!-- 中央仓库,优先拉取公共依赖 -->
    <repository>
        <id>central</id>
        <name>Maven Central</name>
        <url>https://repo1.maven.org/maven2</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>

    <!-- 私有仓库,仅拉取org.csystem组的依赖 -->
    <repository>
        <id>ifsygn-maven-repo</id>
        <name>github maven repo</name>
        <url>https://raw.github.com/ifsygn/ifsygn-maven-repo/main</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <filters>
            <filter>
                <groupId>org.csystem</groupId>
            </filter>
        </filters>
    </repository>
</repositories>

3. 修正父依赖的relativePath配置

删除或修改父依赖中的<relativePath>,让Maven正常从仓库拉取父POM:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.0</version>
    <!-- 移除错误的相对路径配置,让Maven自动从仓库查找 -->
    <relativePath/>
</parent>

4. 验证配置

执行Maven命令同步依赖,确认问题解决:

mvn dependency:resolve

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 14:35:39