配置阿里云镜像
<!-- 多个相同 mirrorOf 的 mirror配置,会根据他们声明的顺序 决定优先级 -->
<!--阿里云仓库地址来源 @see https://developer.aliyun.com/mvn/guide-->
<mirror>
<id>aliyunMaven01</id>
<name>aliyun maven</name>
<!--public地址是central和jcenter的合并地址-->
<url>https://maven.aliyun.com/repository/public</url>
<!--central 表示覆盖 Maven 默认的配置的中央仓库-->
<mirrorOf>central</mirrorOf>
</mirror>
配置私服
私服配置方法一:
增加一个mirror
,注意放在central阿里云仓库后面,多个相同 mirrorOf
的 mirror
配置,会根据``声明的顺序,决定优先级。
<!-- 多个相同 mirrorOf 的 mirror配置,会根据他们声明的顺序 决定优先级 -->
<mirror>
<!--该镜像的唯一标识符。id用来区分不同的mirror元素。 -->
<id>myMirror01</id>
<name>myMirror01</name>
<url>http://xxxxxxx/maven-releases/</url>
<!-- 公共镜像仓库中找不到该jar包时使用私服 -->
<mirrorOf>central</mirrorOf>
</mirror>
私服配置方法二:
- 配置
profile
,并且激活,maven
会按照activeProfiles
激活顺序,设置优先级,先使用前面的仓库配置查询下载 jar - 这里之所以加上aliyun的配置,是因为有时候公司私服设置不当,maven查询检查会以为私服有该jar,但其实没有,导致一直在私服下载jar包,依赖一直下载失败
<profiles>
<profile>
<id>myMirror01</id>
<!--这里配置的repository和pom里面配置的repositories远程仓库一样-->
<repositories>
<repository>
<id>central</id>
<url>http://xxxx/nexus/repository/maven-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>aliyun</id>
<repositories>
<repository>
<id>central</id>
<url>https://maven.aliyun.com/repository/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<!-- 将会按照激活顺序,设置优先级,先使用前面的查询下载 jar-->
<!-- 这里之所以加上aliyun的配置,是因为有时候公司私服设置不当,maven查询检查会以为私服有该jar,但其实没有,导致一直在私服下载jar包,依赖一直下载失败 -->
<activeProfile>aliyun</activeProfile>
<activeProfile>myMirror01</activeProfile>
</activeProfiles>
<!--仓库下载jar包时的选择顺序 -->
<!--本地仓库 > 私服 (profile)> 远程仓库(pom里的repository)和 镜像 (镜像) > 中央仓库 (central)-->
设置本地仓库文件夹目录
<localRepository>F:\myMaven\jar</localRepository>
设置私服访问密码
注意:这里的id
和其他地方的id
要一样,这样才可以对应上
<server>
<id>myMirror01</id>
<username>123456</username>
<password>123456</password>
</server>
下载jar包时各个配置的优先级
maven查找下载jar包时,会按照下面这个优先级进行查询:
本地仓库文件夹 >
私服 (profile
)>
远程仓库(pom
里的repository
)==
镜像 (mirrors
) >
中央仓库 (central
)
可能产生的问题
有时候,明明本地仓库已经包含改jar包,由于本地仓库文件夹有lastUpdated
和_remote.repositories
,导致一直去远程仓库下载,可以参考我的这篇文章