java
主页 > 软件编程 > java >

将maven源改为国内阿里云镜像的教程

2023-12-06 | 佚名 | 点击:

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

1

2

3

4

5

6

7

8

<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源有的包下载不了。所以我建议设置如果阿里云下载不了,就去下载中央库。所以我的设置如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

<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下的哪个仓库,如果是*号,就包含了所有仓库。比如看下图,

原文链接:
相关文章
最新更新