Maven国内源配置

修改Maven中的配置文件。

进入Mavne的安装路径也就是解压路径,例如D:\apache-maven-3.5.4\conf。修改D:\apache-maven-3.5.4\conf下的settings.xml文件

找到<mirrors></mirrors>标签,在其中配置阿里云镜像。

1
2
3
4
5
6
7
8
9
 <mirrors>
     <!--下面是配置内容-->
     <mirror>
      <id>alimaven</id>
      <mirrorOf>central</mirrorOf>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
    </mirror>
  </mirrors>
1
2
3
4
5
6
7
8
<mirrors>
 
    <mirror>
        <id>aliyun-public</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun public</name>
        <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
 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
60
61
  </mirrors>
    <profile>
      <repositories>
        <repository>
            <id>google</id>
            <url>https://maven.aliyun.com/repository/google</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
 
        <repository>
            <id>gradle-plugin</id>
            <url>https://maven.aliyun.com/repository/gradle-plugin</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
 
        <repository>
            <id>spring</id>
            <url>https://maven.aliyun.com/repository/spring</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
 
        <repository>
            <id>spring-plugin</id>
            <url>https://maven.aliyun.com/repository/spring-plugin</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
 
        <repository>
            <id>grails-core</id>
            <url>https://maven.aliyun.com/repository/grails-core</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
 
 
      </repositories>
    </profile>

Gradle国内源配置

针对单个项目比较简单:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
repositories {
    maven {
        url 'https://maven.aliyun.com/repository/public/'
    }
    maven {
        url 'https://maven.aliyun.com/repository/spring/'
    }
    mavenLocal()
    mavenCentral()
}

针对全局项目

在GRADLE_HOME/init.d/目录下新建文件:init.gradle

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
allprojects {
    repositories {
 
        mavenLocal()
 
        maven { url 'https://maven.aliyun.com/repository/public/' }
        maven { url 'https://maven.aliyun.com/repository/spring/'}
      maven { url 'https://maven.aliyun.com/repository/google/'}
      maven { url 'https://maven.aliyun.com/repository/gradle-plugin/'}
      maven { url 'https://maven.aliyun.com/repository/spring-plugin/'}
      maven { url 'https://maven.aliyun.com/repository/grails-core/'}
      maven { url 'https://maven.aliyun.com/repository/apache-snapshots/'}
        
        mavenCentral()
    }
}