idea使用阿里云maven镜像无法下载依赖

错误显示如下:

Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.2.4.RELEASE from/to alimaven (http://maven.aliyun.com/nexus/content/groups/public/): Transfer failed for http://maven.aliyun.com/nexus/content/groups/public/org/springframework/boot/spring-boot-starter-parent/2.2.4.RELEASE/spring-boot-starter-parent-2.2.4.RELEASE.pom

配置阿里云镜像有两种方式,一种是在maven的settings.xml文件中添加阿里云的maven镜像,这种方式是永久的。另一种方式是在本项目pom.xml文件中添加阿里云镜像,这种方式只对当前项目生效。相比之下,用第一种方式更好。如果在pom.xml文件中配置了镜像,会优先使用pom.xml里的镜像。所以用第一种方式就好了。

首先,idea应该使用自己下载的maven,在Settings—>maven里设置本地maven路径,及setting.xml所在的路径。我们主要要修改的就是setting.xml文件。
在这里插入图片描述
将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>C:\Users\16376\.m2\repository</localRepository>
  
    <!-- Apache Maven 配置 -->
    <pluginGroups/>
    <proxies/>

    <!-- 私服发布的用户名密码 -->
    <servers>
        <server>
            <id>releases</id>
            <username>deployment</username>
            <password>He2019</password>
        </server>
        <server>
            <id>snapshots</id>
            <username>deployment</username>
            <password>He2019</password>
        </server>
    </servers>
    
    <!-- 阿里云镜像 -->
    <mirrors>
        <mirror>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <!-- https://maven.aliyun.com/repository/public/ -->
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
    </mirrors>

    <!-- 配置: java8, 先从阿里云下载, 没有再去私服下载  -->
    <!-- 20190929 hepengju 测试结果: 影响下载顺序的是profiles标签的配置顺序(后面配置的ali仓库先下载), 而不是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>

        
        <!-- Nexus私服配置: 第三方jar包下载, 比如oracle的jdbc驱动等 -->
        <profile>
            <id>dev</id>
            <repositories>
                <repository>
                    <id>nexus</id>
                    <url>http://nexus.hepengju.cn:8081/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>public</id>
                    <name>Public Repositories</name>
                    <url>http://nexus.hepengju.cn:8081/nexus/content/groups/public/</url>
                </pluginRepository>
            </pluginRepositories>
        </profile>
        
        <!-- 阿里云配置: 提高国内的jar包下载速度 -->
        <profile>
            <id>ali</id>
            <repositories>
                <repository>
                    <id>alimaven</id>
                    <name>aliyun maven</name>
                    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>alimaven</id>
                    <name>aliyun maven</name>
                    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                </pluginRepository>
            </pluginRepositories>
        </profile>

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

然后reload maven,就开始从阿里云镜像下载了~~

### 配置IntelliJ IDEA项目使用阿里云Maven镜像仓库 为了使 IntelliJ IDEA 项目能够高效地利用阿里云 Maven 镜像仓库来获取依赖项,需按照如下方法操作: #### 修改 `settings.xml` 文件以添加阿里云 Maven 镜像配置 在用户的 `.m2/settings.xml` 或者全局的 `$MAVEN_HOME/conf/settings.xml` 中加入特定的 `<mirrors>` 节点下的 `<mirror>` 子节点。具体来说,在该文件中应包含如下 XML 片段[^4]: ```xml <mirrors> <!-- other mirrors, if any --> <mirror> <id>aliyun-maven</id> <name>Aliyun Maven</name> <url>https://maven.aliyun.com/repository/public</url> <mirrorOf>*</mirrorOf> </mirror> </mirrors> ``` 此片段定义了一个名为 Aliyun Maven 的新镜像,并将其 URL 设置为阿里云公共库地址。 #### 在IDEA内部调整Maven设置 确保所使用IDE 已经指向正确的 Maven 安装路径以及上述已编辑过的 settings.xml 文件位置。这通常可以在项目的结构对话框(File -> Project Structure...),选择 "SDKs" 下对应的 Maven Home Path 和 User Settings file 来完成设定[^1]。 #### 测试配置有效性 通过执行命令 `mvn help:effective-settings` 可验证当前环境是否成功切换到了指定的新镜像源上。这一指令会打印出实际生效的各种配置详情,包括所采用的 mirror 地址等信息[^2]。 #### 示例代码展示如何查看有效配置 ```bash # 执行这条命令可以检查目前有效的setting配置情况 mvn help:effective-settings ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值