前言
在使用maven环境中,有时候在pom.xml
配置,发现配置的<repositories>
不生效
pom.xml配置仓库
有时候在配置pom.xml
文件,会在配置文件里面配置包仓库,例如
<repositories>
<repository>
<id>libs-snapshot</id>
<name>libs-release</name>
<url>仓库地址</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>libs-release</id>
<name>libs-release</name>
<url>仓库地址</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
在settings.xml
中配置了
<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>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.69.166:8081/repository/maven-public/</url>
</mirror>
</mirrors>
这个时候,可以这么配置配置
<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>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>nexus</id>
<mirrorOf>*,!libs-snapshot,!libs-release</mirrorOf>
<url>http://192.168.69.166:8081/repository/maven-public/</url>
</mirror>
</mirrors>
配置!libs-snapshot,!libs-release
,这样配置libs-release
和libs-snapshot
不会从settings.xml
配置仓库中查找
总结
开发中使用`pom.xml`配置仓库,或者直接从`settings.xml`配置,看个人习惯和需求