如何将maven源改为国内阿里云镜像

作者:被吊打的学渣 时间:2023-07-25 13:47:33 

由于众所周知的原因,maven的库在中国大陆非常慢。我在百度上搜到的大部分文章都是直接在~/.m2/settings.xml 加入以下内容

<mirrors>
   <mirror>
   <id>aliyunmaven</id>
   <mirrorOf>central</mirrorOf>
   <name>aliyun maven</name>
   <url>https://maven.aliyun.com/repository/public </url>
   </mirror>
 </mirrors>

其实这样设置,我发现其实镜像并没有改变,还是maven的中央库。在maven库的官网上http://maven.apache.org/settings.html,是建议我们这样设置的。但是我发现,有时候,阿里云maven源有的包下载不了。所以我建议设置如果阿里云下载不了,就去下载中央库。所以我的设置如下:

<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>

还有一个令人困惑的是标签mirrorOf,根据maven官网解释 specify the mirror of setting that is the ID of the repository you are using a mirror of。这句话令人困惑,我猜的意思就是https://maven.aliyun.com/repository/central下的哪个仓库,如果是*号,就包含了所有仓库。比如看下图,

如何将maven源改为国内阿里云镜像

来源:https://zhuanlan.zhihu.com/p/71998219

标签:maven,源,阿里云镜像
0
投稿

猜你喜欢

  • 详解springboot和vue前后端分离开发跨域登陆问题

    2023-08-07 00:48:38
  • Java设计模式之模板方法模式详解

    2021-08-04 04:32:51
  • C#中使用快速排序按文件创建时间将文件排序的源码

    2023-06-04 08:19:19
  • idea中MavenWeb项目不能创建Servlet的解决方案

    2022-07-09 19:26:11
  • C# Assembly.Load案例详解

    2021-11-06 03:20:33
  • idea搭建SSM框架遇踩的坑(附完整过程)

    2023-06-23 09:53:07
  • idea mybatis配置log4j打印sql语句的示例

    2023-11-25 10:32:39
  • Android应用中ListView利用OnScrollListener分页加载数据

    2021-11-06 16:01:04
  • flutter中build.gradle仓库的配置(解决外网下载速度过慢失败的问题)

    2023-06-16 02:07:20
  • 用java等语言仿360首页拼音输入全模糊搜索和自动换肤

    2022-12-28 18:32:01
  • 一篇文章弄懂Java和Kotlin的泛型难点

    2022-11-19 11:37:19
  • 简介Winform中创建用户控件

    2021-10-14 04:39:37
  • Java查找不重复无序数组中是否存在两个数字的和为某个值

    2023-08-22 16:44:40
  • Java递归寻路实现,你真的理解了吗

    2022-09-17 02:24:34
  • Flutter使用Android原生播放器详解

    2023-04-11 20:23:00
  • RocketMq深入分析讲解两种削峰方式

    2023-04-04 01:38:47
  • Flow转LiveData数据丢失原理详解

    2023-05-20 10:22:25
  • Android Touch事件分发过程详解

    2021-08-28 20:11:33
  • 详解Android(共享元素)转场动画开发实践

    2021-09-28 21:33:41
  • 如何在mapper文件中使用in("str1","str2")

    2023-07-10 10:40:51
  • asp之家 软件编程 m.aspxhome.com