周凯,个人博客

  • 前端
  • 嵌入式
  • 工具
  • 后端
  • 随笔
个人记录
  1. 首页
  2. 前端
  3. 正文

maven配置加速镜像

2022年 10月 29日 1422点热度 0人点赞 0条评论

下载

  • maven官网地址

    img

  • 配置环境变量

    • 在配置之前请将JDK安装好。

    • 添加M2_HOME:对应Maven的解压目录即可。

    img

    • 编辑Path环境变量:

    img

    • 添加 %M2_HOME%\bin

      img

    • 测试,在cmd窗口输入mvn -v查看

    • 显示如下即配置成功

      img

为什么慢

执行 mvn 各种命令的时候,默认是去 maven 官方镜像源获取需要安装的具体软件信息

默认源地址在国外,从国内访问的速度肯定比较慢

方法一: 配置只在当前项目生效

  • 在 pom.xml 文件内添加以下配置

    
      
          ali-maven
          http://maven.aliyun.com/nexus/content/groups/public
      
    

方法二: 配置全局生效

  • 修改 settings.xml 文件

    • 找到 mirrors 标签,在里面加入以下内容
    
        alimaven
        aliyun maven
        http://maven.aliyun.com/nexus/content/groups/public/
        central
    
  • 可以在以下路径查找到 settings.xml 文件

    1. (用户家目录)/.m2/settings.xml

    2. (maven 安装目录)/conf/settings.xml,

      如果是 Mac 系统通过 brew 命令安装的,在这里:

      /usr/local/Cellar/maven/(版本号)/libexec/conf/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/>
  <interactiveMode/>
  <usePluginRegistry/>
  <offline/>
  <pluginGroups/>
  <servers/>
  <mirrors>
    <mirror>
     <id>aliyunmaven</id>
     <mirrorOf>central</mirrorOf>
     <name>阿里云公共仓库</name>
     <url>https://maven.aliyun.com/repository/central</url>
    </mirror>
    <mirror>
      <id>repo1</id>
      <mirrorOf>central</mirrorOf>
      <name>central repo</name>
      <url>http://repo1.maven.org/maven2/</url>
    </mirror>
    <mirror>
     <id>aliyunmaven</id>
     <mirrorOf>apache snapshots</mirrorOf>
     <name>阿里云阿帕奇仓库</name>
     <url>https://maven.aliyun.com/repository/apache-snapshots</url>
    </mirror>
  </mirrors>
  <proxies/>
  <activeProfiles/>
  <profiles>
    <profile>  
        <repositories>
           <repository>
                <id>aliyunmaven</id>
                <name>aliyunmaven</name>
                <url>https://maven.aliyun.com/repository/public</url>
                <layout>default</layout>
                <releases>
                        <enabled>true</enabled>
                </releases>
                <snapshots>
                        <enabled>true</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>MavenCentral</id>
                <url>http://repo1.maven.org/maven2/</url>
            </repository>
            <repository>
                <id>aliyunmavenApache</id>
                <url>https://maven.aliyun.com/repository/apache-snapshots</url>
            </repository>
        </repositories>             
     </profile>
  </profiles>
</settings>

🎯 拓展阅读提示

本文涉及的内容已同步至公众号后台,我会在那里分享更多深度内容和实用技巧

→ 点击关注:一行梦境

公众号二维码
本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: maven
最后更新:2022年 10月 29日

周凯

这个人很懒,什么都没留下

打赏 点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2022-现在 周凯,个人博客. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

蒙ICP备18004897号