JetBrains IDEA 更新Maven的repository失败的解决方案

JetBrains IDEA 更新Maven的repository失败的解决方案

最近使用IDEA更新repository的时候,更新失败:

原因是配置了阿里云的镜像,但阿里云的镜像中并不包含仓库的index索引文件。

解决办法:

  1. 将配置的阿里云镜像暂时注释掉,使用原生的maven中央仓库进行更新,但速度会比较慢,一般会因为超时而失败,如果速度很快就不需要使用镜像了
  2. 配置华为云支持index的源仓库(推荐)
    使用华为云的settings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

    <!-- 本地仓库的位置 -->
    <localRepository>d:/cache/.m2/repository</localRepository>

    <!-- Apache Maven 配置 -->
    <pluginGroups/>
    <proxies/>

    <mirrors>
        <mirror>
            <id>huaweicloud</id>
            <mirrorOf>*</mirrorOf>
            <url>https://repo.huaweicloud.com/repository/maven/</url>
        </mirror>
    </mirrors>

    <!-- 测试结果: 影响下载顺序的是profiles标签的配置顺序(后面的优先级更高),而不是activeProfiles的顺序 -->
    <profiles>
        <!-- 全局JDK1.8配置 -->
        <profile>
            <id>jdk1.8</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
            </activation>
            <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            </properties>
        </profile>
    </profiles>

    <!-- 激活配置 -->
    <activeProfiles>
        <activeProfile>jdk1.8</activeProfile>
    </activeProfiles>
</settings>

将阿里云的镜像修改为华为云之后,下载就成功了,速度也很快:

更多关于maven仓库的了解可以查看:详解Maven的setting配置文件中mirror和repository的区别

posted @ 2022-11-09 11:17  yangwen0228  阅读(2909)  评论(0编辑  收藏  举报