Tag

Maven

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>

如何查找Maven/Gradle依赖

开发工具

阿里云(推荐)

如何使用阿里云镜像

搜索依赖 https://developer.aliyun.com/mvn/search

搜索依赖有两种模式,一种是使用关键词的搜索,另一种是知道依赖的group和artifact的情况下精准搜索

关键词

精准搜索

精准搜索时可以只填一个参数模糊匹配

这里点击蓝色的依赖名字,可以打开如下界面

这里也可以直接生成maven的依赖(虽然没有生成gradle格式的依赖,但是在IDEA中直接复制到build.gradle中是可以自动转换格式的)

中央仓库(不翻墙需要过人机验证)

搜索依赖 https://mvnrepository.com/

首先搜索,找到自己要的依赖并打开

找到自己需要的版本打开

可以看到此处显示了依赖的详细信息,下方还会自动生成各种格式的依赖,可以直接复制到项目里