学习maven 知识点
1、maven 镜像是什么? 作用? 怎么用? 有那些可待选择用
(1)、镜像是什么?
如果仓库X可以提供仓库Y存储的所有内容,那么就可以认为仓库X是仓库Y的一个镜像(mirror),换句话说,任何一个可以从Y中获取到的构件够可以从X中获取到 如果配置了 mirror
<mirrorOf>的值为central,表示该配置为中央仓库的镜像,任何对于中央仓库的请求,都会转到对应的镜像url中请求对应的资源,用户也可以使用同样的方法配置其他仓库的镜像
(2)、为什么需要配置maven 国内镜像
A、如果不配置国内镜像,maven 会默认使用国外中央库
B、中央库在国外,访问非常慢,下载依赖,可能出现无法下载情况
(3)、 怎么配置maven 镜像?
A、在settings.xml 中进行配置,这种方式对所有的maven 工程有效,但是在升级maven版本的时候,需要注意要把已经配置好的settings.xml 复制到新的maven目录下 (这里举例是 阿里云的仓库)
- <mirrors>
- <!-- mirror
- | Specifies a repository mirror site to use instead of a given repository. The repository that
- | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
- | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
- |
- -->
- <mirror>
- <id>alimaven</id>
- <name>aliyun maven</name>
- <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
- <mirrorOf>central</mirrorOf>
- </mirror>
- </mirrors>
B、在每个项目的 porm.xml 配置,此配置方式只对本工程有效,建议第一种方式
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository>
(4)、 推荐几个好用的maven 镜像
https://blog.****.net/lovoo/article/details/77881467
2、 关于 update maven project 时,勾选 force update of snapshots/releases 注意事项
这个 描述意思是:强制更新快照/版本 就要牵扯到 snapshot版本
snapshot版本使用注意事项:
1、A、B工程在同一eclipse工作区中,A的pom中依赖了B.jar
若不在eclipse关闭B工程,A工程maven->update project时候 不会更新快照版本的jar 会直接引用工作区中的B工程,而非B.jar。
解决办法:将B工程,右键->close project。然后如图,update maven project 中勾选force update of snapshots/releases。这样工程就会自动下载最新的snapshot版本。