(1),在本地仓库中寻找,如果没有则进入下一步。
(2),在全局配置的私服仓库(settings.xml中配置的并有激活)中寻找,如果没有则进入下一步。
(3),在项目自身配置的私服仓库(pom.xml)中寻找,如果没有则进入下一步。
(4),在中央仓库中寻找,如果没有则终止寻找
默认中央仓库的地址:
https://repo1.maven.org/maven2/
在中国访问仓库比较慢,一般替换为阿里云的中央仓库
可以直接修改Maven conf文件夹中的setting.xml文件
setting.xml里面有个mirrors节点,用来配置镜像URL。mirrors可以配置多个mirror,每个mirror有id,name,url,mirrorOf属性。
mirror也不是按settings.xml中写的那样的顺序来查询的。所谓的第一个并不一定是最上面的那个。
当有id为B,A,C的顺序的mirror在mirrors节点中,maven会根据字母排序来指定第一个,所以不管怎么排列,一定会找到A这个mirror来进行查找,当A无法连接,出现意外的情况下,才会去B查询。
<mirrors>
<mirror>
<id>nexus-ali</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<repositories>
<repository>
<id>nexus-ali</id>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository>
</repositories>
(1)在私服的后台设置仓库的镜像地址(用于私服不存在时候从该地址下载)
(2)修改maven的settings.xml的配置文件:配置下载地址 在<profiles>里配置,同时激活两个,可以从两个地址下载
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<name>Nexus Repository</name>
<url>http://10.110.16.44:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>Nexus pluginRepository</name>
<url>http://10.110.16.44:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>nexus-ali</id>
<repositories>
<repository>
<id>nexus-ali</id>
<name>ali mirror central</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-ali</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
<activeProfiles>
<activeProfile>nexus</activeProfile>
<activeProfile>nexus-ali</activeProfile>
</activeProfiles>
1.在 pom 文件中添加如下代码
<distributionManagement>
<repository>
<id>releases</id>
<name>Releases</name>
<url>http://10.110.16.44:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Snapshot</name>
<url>http://10.110.16.44:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
2.setting文件里设置
<servers>
<server>
<id>releases</id> 对应pom 文件的id
<username>admin</username> 私服用户名
<password>admin111</password> 私服密码
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin111</password>
</server>
</servers>
注意:如果是快照版本,那么在mvn deploy时会自动发布到快照版本库中,会覆盖老的快照版本,而在使用快照版本的模块,在不更改版本号的情况下,直接编译打包时,maven会自动从镜像服务器上下载最新的快照版本。如果是正式发布版本,那么在mvn deploy时会自动发布到正式版本库中,而使用正式版本的模块,在不更改版本号的情况下,编译打包时如果本地已经存在该版本的模块则不会主动去镜像服务器上下载。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。