目的
记录下自己在项目实际使用时遇见的问题,不做科普,仅为记录!!!
依赖查找顺序
- 在本地仓库中寻找
- 在全局配置的远程仓库(settings.xml中配置的并有激活)中寻找(如果被mirror拦截,则从mirror查询)
- 在项目自身配置的远程仓库(pom.xml)中寻找(如果被mirror拦截,则从mirror查询)
- 在中央仓库中寻找(如果被mirror拦截,则从mirror查询)
如果在找寻的过程中,如果发现该仓库有镜像设置,则用镜像的地址代替。例如现在进行到要在respository A仓库中查找某个依赖,但A仓库配置了mirror,则会转到从A的mirror中查找该依赖,不会再从A中查找。
settings.xml中配置的profile(激活的)下的respository优先级高于项目中pom文件配置的respository。
如果仓库的id设置成“central”,则该仓库会覆盖maven默认的中央仓库配置
Maven 镜像配置 mirror
简单而言, mirror可以拦截对远程仓库的请求 , 改变对目标仓库的下载地址。
如果mavensetting.xml中配置了镜像 , 而且镜像配置的规则中匹配到目标仓库时 ,
maven认为目标仓库被镜像了, 不会再去被镜像仓库下载依赖jar包, 而是直接去镜像仓库下载。
下面是真实的镜像配置:
<mirror> <id>nexus-aliyun</id> <mirrorOf>*</mirrorOf> //代理仓库配置 <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror>
mirrorOf * 就意味着匹配所有的仓库,拦截maven对仓库的请求,将对真实仓库请求的地址更改为镜像地址。
配置mirrorof 有多种形式:
mirrorOf=“*” //mirror一切,所有仓库请求全部重定向到镜像地址
mirrorOf=repo-1 //镜像repo-1,对repo-1仓库访问重定向到镜像地址
mirrorOf=*,!repo-1 //!表示非运算,排除你配置的repo-1仓库,其他仓库都被镜像了。
mirrorOf=external:* //如果本地库存在就用本地库的,如果本地没有所有下载就用mirror配置的url下载
Maven的profile配置
项目中经常会在Maven中setting文件中配置profile,具体配置如下:
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://xxx/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>xxx-snapshots</id>
<url>https://xxx/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
个人理解:
profile是maven用来隔离不同环境的配置,例如:
<repositories>
<pluginRepositories>
<dependencies>
<plugins>
<properties>
<modules>
<reporting>
<dependencyManagement>
<distributionManagement>