首页 > 其他分享 >maven 加载顺序

maven 加载顺序

时间:2022-08-30 10:00:24浏览次数:41  
标签:xml 顺序 http 仓库 maven nexus 加载

转载 http://uoften.com/article/216374.html

概述

本文主要是关于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:programsapache-maven-3.6.1-binnotify_repo
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for D:programsapache-maven-3.6.1-binnotify_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级别日志:

标签:xml,顺序,http,仓库,maven,nexus,加载
From: https://www.cnblogs.com/mytdbky/p/16638266.html

相关文章