阅读 263

Maven仓库加载顺序(修改maven本地仓库位置)

Maven仓库一般分为本地仓库和远程仓库。远程仓库又分为私服、中央仓库、中央仓库的镜像仓库。

本地仓库就是本地维护的maven仓库,仅为本机项目提供服务。

私服一般是公司或组织在局域网级别搭建的maven仓库,服务范围是公司或组织局域网内的成员。

镜像仓库,这里指的是maven中央仓库的镜像仓库。分布在全球各个地方,是maven中央仓库的镜像备份。镜像仓库的作用一是分摊中央仓库的访问压力,第二就是可以提升我们下载依赖的速度。常用的镜像仓库有阿里云镜像仓库等等。

那么在实际开发中,在配置了多个仓库的情况下,他们之间的加载访问顺序是怎么样的呢?

本地仓库 》 私服 》 镜像仓库

可以通过配置来验证一下:
pom.xml配置仓库:

 <repositories> <repository> <id>local-nexus</id> <url>http://xxx.xxx.xxx.135:8081/nexus/repository/maven-group-snapshots/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> <repository> <id>ali-maven</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> 复制代码

setting.xml配置仓库:

   <!-- 这里配置的阿里云的镜像仓库来替代maven中央仓库 -->   <mirrors>     <mirror>         <id>alimaven</id>         <name>aliyun maven</name>         <url>http://maven.aliyun.com/nexus/content/groups/public/</url>         <mirrorOf>central</mirrorOf>               </mirror>   </mirrors> 复制代码

compile一下:

... //优先加载本地仓库 [DEBUG] Using local repository at D:\programs\apache-maven-3.6.1-bin\notify_repo [DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for D:\programs\apache-maven-3.6.1-bin\notify_repo [INFO] Scanning for projects... //这里使用setting.xml配置的阿里云中央仓库代替maven中央仓库 [DEBUG] Using mirror alimaven (http://maven.aliyun.com/nexus/content/groups/public/) for central (https://repo.maven.apache.org/maven2). ... 复制代码

... //可以看到这是远程仓库加载的顺序,先是加载pom.xml配置的135私服,然后是ali-maven,最后才是setting.xml中的alimavn,在pom.xml中,可以通过调整<repository>的顺序来调整私服的加载顺序 [DEBUG] Repositories (dependencies):  [local-nexus (http://xxx.xxx.xxx.135:8081/nexus/repository/maven-group-snapshots/, default, releases+snapshots),  ali-maven (http://maven.aliyun.com/nexus/content/groups/public/, default, releases+snapshots),  alimaven (http://maven.aliyun.com/nexus/content/groups/public/, default, releases)] ... 复制代码

这里说的、以及setting.xml中的并不能代表实际中出现的所有配置,具体加载顺序还是得看具体的项目和maven配置,这些都不是重点,重点是可以通过日志来知道实际是什么情况的。

最后,如何在idea中开启maven的debug级别日志:

maven-debug.png


作者:情愿
链接:https://juejin.cn/post/7046943196869296158


文章分类
代码人生
文章标签
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐