文章目录
- 1. 配置maven的settings.xml文件
- 1.1. 先把镜像mirror配置好
- 1.2. 再把仓库配置好
- 2. 在idea中引用
- 3. 参考资料
网上配置maven国内镜像的文章很多,为什么选择我,原因是:一次配置得永生、仓库覆盖广、仓库覆盖全面、作者自用的配置。
1. 配置maven的settings.xml文件
1.1. 先把镜像mirror配置好
复制就完事了
<mirrors>
<mirror>
<id>aliyun-central</id>
<!-- 一定不能用*,否则所有的都会被拦截,哪怕在这个仓库找不到依赖 -->
<mirrorOf>central</mirrorOf>
<name>aliyun central</name>
<url>https://maven.aliyun.com/repository/central</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>
1.2. 再把仓库配置好
复制就完事了
<profile>
<!-- 默认的项目编译环境 -->
<id>jdk1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
<!-- 所有的镜像仓库 -->
<repositories>
<repository>
<id>aliyun-public</id>
<name>aliyun public</name>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>aliyun-spring</id>
<name>aliyun spring</name>
<url>https://maven.aliyun.com/repository/spring</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>aliyun-spring-plugin</id>
<name>aliyun spring-plugin</name>
<url>https://maven.aliyun.com/repository/spring-plugin</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>aliyun-apache-snapshots</id>
<name>aliyun apache-snapshots</name>
<url>https://maven.aliyun.com/repository/apache-snapshots</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>aliyun-google</id>
<name>aliyun google</name>
<url>https://maven.aliyun.com/repository/google</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>aliyun-gradle-plugin</id>
<name>aliyun gradle-plugin</name>
<url>https://maven.aliyun.com/repository/gradle-plugin</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>aliyun-jcenter</id>
<name>aliyun jcenter</name>
<url>https://maven.aliyun.com/repository/jcenter</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>aliyun-releases</id>
<name>aliyun releases</name>
<url>https://maven.aliyun.com/repository/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>aliyun-snapshots</id>
<name>aliyun snapshots</name>
<url>https://maven.aliyun.com/repository/snapshots</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>aliyun-grails-core</id>
<name>aliyun grails-core</name>
<url>https://maven.aliyun.com/repository/grails-core</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>aliyun-mapr-public</id>
<name>aliyun mapr-public</name>
<url>https://maven.aliyun.com/repository/mapr-public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
2. 在idea中引用
如下图在框框处引用你自己的maven本地地址,点击应用点击OK。然后重新刷新您的maven项目看看是不是在下载jar包。
3. 参考资料
idea不自动生成target
Maven配置国内镜像