Tag

镜像源

Maven设置阿里云镜像源

开发工具

win: C:\Users\用户名\.m2

linux: /home/用户名/.m2

正常情况下在此文件夹下会有

  1. repository:存放下载的依赖
  2. settings.xml:maven的配置

此处的settings.xml就是需要设置的文件,若没有可自行新建

下面贴出我的设置

xml
<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
                          https://maven.apache.org/xsd/settings-1.0.0.xsd">
  	<!-- 设置储存库位置 -->
    <localRepository>D:/.m2/repository</localRepository>
    <!-- 设置下载源 -->
  	<mirrors>
      	<!-- 阿里云 -->
		<mirror>  
			<id>nexus-aliyun</id>  
			<mirrorOf>central</mirrorOf>    
			<name>Nexus aliyun</name>  
			<url>http://maven.aliyun.com/nexus/content/groups/public</url>  
		</mirror>
		<!-- 默认仓库 -->
		<mirror>
			<id>repo1</id>
			<mirrorOf>central</mirrorOf>
			<name>Human Readable Name for this Mirror.</name>
			<url>http://repo1.maven.org/maven2/</url>
		</mirror>
		<mirror>
			<id>repo2</id>
			<mirrorOf>central</mirrorOf>
			<name>Human Readable Name for this Mirror.</name>
			<url>http://repo2.maven.org/maven2/</url>
		</mirror>
	</mirrors>
</settings>

Gradle设置阿里云镜像源

开发工具

Gradle设置

首先找到Gradle的用户目录,默认情况下在 C:\Users\你的用户名\.gradle

如果设置了 GRADLE_HOME 环境变量的话就是你设置的目录

找到家目录中的 init.gradle 文件,如果没有就新建一个

在其中添加如下代码

纯文本
buildscript {
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/public'
        }
        maven {
            url 'https://maven.aliyun.com/repositories/jcenter'
        }
    }
}

allprojects {
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/public'
        }
        maven {
            url 'https://maven.aliyun.com/repositories/jcenter'
        }
    }
}

仓库名

简介

实际地址

使用地址

jcenter

JFrog公司提供的仓库

http://jcenter.bintray.com

https://maven.aliyun.com/repository/jcenter
https://maven.aliyun.com/nexus/content/repositories/jcenter

mavenLocal

本台电脑上的仓库

{USER_HOME}/.m2/repository

C:/Users/{USER_NAME}/.m2/repository (Windows)
/home/{USER_NAME}/.m2/repository (Linux)

mavenCentral

Sonatype公司提供的中央库

http://central.maven.org/maven2

https://maven.aliyun.com/repository/central
https://maven.aliyun.com/nexus/content/repositories/central

google

Google公司提供的仓库

https://maven.google.com

https://maven.aliyun.com/repository/google
https://maven.aliyun.com/nexus/content/repositories/google
https://dl.google.com/dl/android/maven2

jitpack

JitPack提供的仓库

https://jitpack.io

https://jitpack.io

public

jcenter和mavenCentral的聚合仓库

https://maven.aliyun.com/repository/public
https://maven.aliyun.com/nexus/content/groups/public

gradle-plugin

Gradle插件仓库

https://plugins.gradle.org/m2

https://maven.aliyun.com/repository/gradle-plugin
https://maven.aliyun.com/nexus/content/repositories/gradle-plugin