Maven下载依赖的顺序及配置文件说明

在 Maven 中,当下载依赖项时,存在多个仓库时会按照以下优先级顺序进行搜索:

本地仓库:Maven 会首先在本地的 Maven 仓库中查找依赖项。

私有仓库(私服):如果在本地仓库中未找到依赖项,Maven 会按照项目的 pom.xml 文件中配置的 元素指定的顺序依次搜索私有仓库。私有仓库是你在项目中添加的自定义仓库,通常是用于存放项目内部开发的依赖项或者第三方库,它可以是一个本地服务器或者其他网络位置。

中央仓库(Maven Central Repository):Maven 中央仓库是 Maven 官方维护的集中存储库,包含了大量常用的开源 Java 项目的构件和元数据。如果项目的 pom.xml 文件没有指定其他远程仓库,并且本地仓库中也没有所需的依赖项,Maven 会自动搜索中央仓库来下载依赖项。

其他远程仓库:如果在项目的 pom.xml 文件中配置了其他远程仓库地址,并且中央仓库、私有仓库和本地仓库都没有所需的依赖项,Maven 会按照 中指定的顺序依次搜索这些自定义远程仓库。

综上所述,Maven 下载依赖项的优先级顺序为:本地仓库 > 远程仓库(包括中央仓库) > 自定义远程仓库。Maven 会按照这个顺序查找依赖项,直到找到所需的依赖或者搜索完所有配置的仓库。如果依赖项在某个仓库中找到了,Maven 会将其下载到本地仓库,并在后续构建过程中直接使用本地仓库中的依赖,以加快构建速度和确保依赖项的一致性。

Maven的配置文件说明

<?xml version="1.0" encoding="UTF-8"?><!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
--><!--| This is the configuration file for Maven. It can be specified at two levels:||  1. User Level. This settings.xml file provides configuration for a single user, |                 and is normally provided in ${user.home}/.m2/settings.xml.||                 NOTE: This location can be overridden with the CLI option:||                 -s /path/to/user/settings.xml||  2. Global Level. This settings.xml file provides configuration for all Maven|                 users on a machine (assuming they're all using the same Maven|                 installation). It's normally provided in |                 ${maven.home}/conf/settings.xml.||                 NOTE: This location can be overridden with the CLI option:||                 -gs /path/to/global/settings.xml|| The sections in this sample file are intended to give you a running start at| getting the most out of your Maven installation. Where appropriate, the default| values (values used when the setting is not specified) are provided.||-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"><!-- localRepository| The path to the local repository maven will use to store artifacts.|| Default: ${user.home}/.m2/repository本地仓库地址--><localRepository>D:\Program Files\localMavenRepoistory</localRepository><!-- interactiveMode| This will determine whether maven prompts you when it needs input. If set to false,| maven will use a sensible default value, perhaps based on some other setting, for| the parameter in question.|| Default: true<interactiveMode>true</interactiveMode>--><!-- offline| Determines whether maven should attempt to connect to the network when executing a build.| This will have an effect on artifact downloads, artifact deployment, and others.|| Default: false<offline>false</offline>--><!-- pluginGroups| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.|--><pluginGroups><!-- pluginGroup| Specifies a further group identifier to use for plugin lookup.<pluginGroup>com.your.plugins</pluginGroup>--></pluginGroups><!-- proxies| This is a list of proxies which can be used on this machine to connect to the network.| Unless otherwise specified (by system property or command-line switch), the first proxy| specification in this list marked as active will be used.|--><proxies><!-- proxy| Specification for one proxy, to be used in connecting to the network.|<proxy><id>optional</id><active>true</active><protocol>http</protocol><username>proxyuser</username><password>proxypass</password><host>proxy.host.net</host><port>80</port><nonProxyHosts>local.net|some.host.com</nonProxyHosts></proxy>--></proxies><!-- servers| This is a list of authentication profiles, keyed by the server-id used within the system.| Authentication profiles can be used whenever maven must make a connection to a remote server.|--><servers><!-- server| Specifies the authentication information to use when connecting to a particular server, identified by| a unique name within the system (referred to by the 'id' attribute below).| 在 Maven 中,<server> 元素用于配置认证信息,主要是用于在构建过程中访问需要认证的远程仓库或资源当使用 Maven 构建项目时,有些远程仓库可能需要进行身份验证(例如私有仓库),这时候就需要提供访问该仓库的用户名和密码。为了不将用户名和密码明文写在 pom.xml 文件中,可以将认证信息放在 Maven的 settings.xml 文件中的 <servers> 元素中| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are |       used together.|<server><id>deploymentRepo</id><username>repouser</username><password>repopwd</password></server>在上述示例中,配置了一个 <server> 元素,它的 <id> 是 "deploymentRepo",表示该认证信息用于访问 ID 为 "deploymentRepo" 的远程仓库。然后,通过 <username> 和 <password> 元素分别提供用户名和密码,这些信息将用于在访问远程仓库时进行身份验证。
当 Maven 需要访问远程仓库或资源时,会检查 settings.xml 文件中的 <servers> 元素,如果有匹配的 <server> 元素(根据 <id> 属性匹配),
就会使用该认证信息进行访问。这样,就可以安全地在 settings.xml 文件中管理认证信息,而不需要在 pom.xml 文件中明文暴露用户名和密码。--><!-- Another sample, using keys to authenticate.<server><id>siteServer</id><privateKey>/path/to/private/key</privateKey><passphrase>optional; leave empty if not used.</passphrase></server>--><server><id>releases</id><username>zs</username><password>pp</password></server><server><id>snapshots</id><username>zs</username><password>pp</password></server><server><id>docker.r.io</id><username>zs</username><password>pp</password></server></servers><!-- mirrors| This is a list of mirrors to be used in downloading artifacts from remote repositories.| | It works like this: a POM may declare a repository to use in resolving certain artifacts.| However, this repository may have problems with heavy traffic at times, so people have mirrored| it to several places.|| That repository definition will have a unique id, so we can create a mirror reference for that| repository, to be used as an alternate download site. The mirror site will be the preferred | server for that repository.|--><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<mirror><id>public</id><name>Nexus Public Mirror</name><url>http://repo.thunisoft.com/maven2/content/groups/public-repo/</url><mirrorOf>central</mirrorOf></mirror><mirror><id>nexus</id><mirrorOf>public-snapshots</mirrorOf><url>http://repo.thunisoft.com/maven2/content/groups/public-snapshots/</url></mirror>--><!--镜像仓库(Mirror Repository)是一种用于加速依赖项下载的机制。在 Maven 中,当你构建项目时,通常需要从远程仓库下载各种依赖项(JAR 文件、插件等)。这些远程仓库可能分布在全球各地,下载速度可能受到网络延迟和带宽限制的影响,导致构建过程较慢。
为了解决这个问题,Maven 允许配置一个镜像仓库,它是一个位于本地网络或高速服务器上的代理仓库。当你配置了镜像仓库后,Maven 将优先尝试从镜像仓库下载依赖项,而不是直接从远程仓库下载。
如果镜像仓库中已经存在所需的依赖项,下载速度将大大加快,因为镜像仓库通常位于本地网络或高速服务器上,与开发者的构建环境更近,网络延迟较小。
镜像仓库不保存所有的依赖项,它只会缓存从远程仓库下载的依赖项。当 Maven 需要下载依赖项时,首先尝试从镜像仓库获取。
如果在镜像仓库中找不到所需的依赖项,Maven 会继续从配置的其他远程仓库下载。--><mirror><id>rep</id><!-- 用于指定该镜像仓库代理的目标仓库。它的作用是告诉 Maven 该镜像仓库要替代哪个远程仓库的下载请求。 当前配置表示这个镜像仓库将代理所有远程仓库的请求,但会排除掉 ID 分别为 "private1"、"private2" 和 "private3" 的远程仓库,这些仓库的请求将不会由这个镜像仓库来处理。这样的配置是有用的,例如,当你有多个私有仓库,并且想要一个镜像仓库来加速下载公共仓库的依赖项,同时不影响私有仓库的下载请求。通过排除私有仓库的 ID,确保私有仓库的请求不会被这个镜像仓库所代理,避免了可能出现的下载问题--><mirrorOf>*,!private1,!private2,!private3</mirrorOf><url>http://maven.r.io/</url></mirror></mirrors><!-- profiles| This is a list of profiles which can be activated in a variety of ways, and which can modify| the build process. Profiles provided in the settings.xml are intended to provide local machine-| specific paths and repository locations which allow the build to work in the local environment.|| For example, if you have an integration testing plugin - like cactus - that needs to know where| your Tomcat instance is installed, you can provide a variable here such that the variable is | dereferenced during the build process to configure the cactus plugin.|| As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles| section of this document (settings.xml) - will be discussed later. Another way essentially| relies on the detection of a system property, either matching a particular value for the property,| or merely testing its existence. Profiles can also be activated by JDK version prefix, where a | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.| Finally, the list of active profiles can be specified directly from the command line.|| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact|       repositories, plugin repositories, and free-form properties to be used as configuration|       variables for plugins in the POM.|Profile是一种用于在不同环境或需求下为项目定义不同配置选项的机制。通过使用 Profile,你可以根据不同的情况激活或禁用特定配置,从而实现项目的定制化构建|--><profiles><profile><id>env1</id><!-- 在 Maven 的 Profile 中,你可以通过 <repositories> 元素来定义特定的仓库配置。这允许你在不同的环境或需求下为项目指定不同的远程仓库,从而实现定制化的依赖管理 --><repositories><repository><id>releases</id><url>http://xxxxxx</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories><pluginRepositories><pluginRepository><id>rep-plugin</id><url>http://xxxxxxxx</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></pluginRepository></pluginRepositories></profile><!-- profile| Specifies a set of introductions to the build process, to be activated using one or more of the| mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>| or the command line, profiles have to have an ID that is unique.|| An encouraged best practice for profile identification is to use a consistent naming convention| for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.| This will make it more intuitive to understand what the set of introduced profiles is attempting| to accomplish, particularly when you only have a list of profile id's for debug.|| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.<profile><id>jdk-1.4</id><activation><jdk>1.4</jdk></activation><repositories><repository><id>jdk14</id><name>Repository for JDK 1.4 builds</name><url>http://www.myhost.com/maven/jdk14</url><layout>default</layout><snapshotPolicy>always</snapshotPolicy></repository></repositories></profile>--><!--| Here is another profile, activated by the system property 'target-env' with a value of 'dev',| which provides a specific path to the Tomcat instance. To use this, your plugin configuration| might hypothetically look like:|| ...| <plugin>|   <groupId>org.myco.myplugins</groupId>|   <artifactId>myplugin</artifactId>|   |   <configuration>|     <tomcatLocation>${tomcatPath}</tomcatLocation>|   </configuration>| </plugin>| ...|| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to|       anything, you could just leave off the <value/> inside the activation-property.|<profile><id>env-dev</id><activation><property><name>target-env</name><value>dev</value></property></activation><properties><tomcatPath>/path/to/tomcat/instance</tomcatPath></properties></profile>--></profiles><!-- activeProfiles| List of profiles that are active for all builds.|激活指定的环境<activeProfiles><activeProfile>alwaysActiveProfile</activeProfile><activeProfile>anotherAlwaysActiveProfile</activeProfile></activeProfiles>--><activeProfiles><activeProfile>env1</activeProfile></activeProfiles>
</settings>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/3325.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

编程导航算法村第二关 | 白银挑战

编程导航算法村第二关 | 白银挑战 指定区间的链表翻转 LeetCode92 &#xff1a;给你单链表的头指针 head 和两个整数 left 和 right &#xff0c;其中 left < right。请你反转从位置 left 到位置 right 的链表节点&#xff0c;返回反转后的链表。 public ListNode revers…

第四次CCF计算机软件能力认证

第一题&#xff1a;图像旋转 旋转是图像处理的基本操作&#xff0c;在这个问题中&#xff0c;你需要将一个图像逆时针旋转 90 度。 计算机中的图像表示可以用一个矩阵来表示&#xff0c;为了旋转一个图像&#xff0c;只需要将对应的矩阵旋转即可。 输入格式 输入的第一行包含两…

我国版式文档格式OFD前端WEB展示之EasyOFD

EasyOFD an ofd file web shower 一个在web端展示ofd文件的控件&#xff0c;该控件基于CANVAS绘制。 该控件使用了以下外部程序 1&#xff09;jszip&#xff1a;解决解压文件。 2&#xff09;x2js: 解决XML文件到JS转换 3&#xff09;easyjbig2: 解决ofd内部使用jb2文件存储的…

NSSCTF刷web(2)

[NISACTF 2022]bingdundun~ bingdundun处感觉像文件包含,改upload为index 发现确实,猜测会补一个后缀.php 那常规文件包含都不行了,这里还有一个文件上传的功能,考虑phar协议 <?php$phar new Phar("test.phar"); $phar->startBuffering(); $phar->setStu…

小马识途分享百度百科收录词条的规则

百度百科词条是人人都可以编辑的&#xff0c;并且都是免费创建&#xff0c;但是自己创建百科词条往往审核不通过&#xff0c;一般企业会把这项任务委托给有经验的营销团队。这里小马识途营销顾问分享一下百度百科收录词条的规则。 百度百科收录规则主要分为&#xff1a;规范词条…

【excel细碎小知识点】

目录索引 &符号的用法&#xff1a;实例演示&#xff1a; 数字显示和位数的区别&#xff1a;分列功能的妙用&#xff1a;什么叫做常规类型&#xff1a; &符号的用法&#xff1a; **连接字符串:**转化后都是文本字符串类型。你可以通过修改数据类型进行更多可能的操作 实…

【Go语言开发】简单了解一下搜索引擎并用go写一个demo

写在前面 这篇文章我们一起来了解一下搜索引擎的原理&#xff0c;以及用go写一个小demo来体验一下搜索引擎。 简介 搜索引擎一般简化为三个步骤 爬虫&#xff1a;爬取数据源&#xff0c;用做搜索数据支持。索引&#xff1a;根据爬虫爬取到的数据进行索引的建立。排序&#xf…

prometheus调整默认数据存储时间

调整kubernetes部署的prometheus数据存储时间 由于prometheus是用kuberentes部署的&#xff0c;没办法像传统部署方式那种直接在启动参数增加存储时间的参数。需要在configmap里或者在deployment里添加&#xff0c;我这里使用的方式是在deployement里添加调整存储时间的参数。…

学会在重装系统前如何备份软件,再也不怕失去珍贵的应用!

​Windows系统是电脑的重要组成部分&#xff0c;它不仅提供了友好的用户界面&#xff0c;还承担着许多关键的功能和任务&#xff0c;为我们提供了一个稳定、安全和效率的工作环境&#xff0c;使我们能够充分发挥电脑的潜力&#xff0c;优化工作效率和生活品质。 随着系统使…

为 GitHub 设置 SSH 密钥

1. 起因 给自己的 github 改个名&#xff0c;顺便就给原来 Hexo 对应的仓库也改了个名。然后发现 ubhexo clean && hexo generate && hexo deploy 失败了&#xff0c;报错如下&#xff1a; INFO Deploying: git INFO Clearing .deploy_git folder... INFO …

软件渗透测试真的很重要吗?渗透测试有哪些测试流程?

软件渗透测试是指通过模拟恶意攻击者的行为&#xff0c;评估软件系统中的潜在安全漏洞和弱点的活动。这种安全测试方法能够帮助开发人员和系统管理员发现并修复潜在的安全漏洞&#xff0c;以确保软件系统的安全性和完整性。软件渗透测试是一项高度技术性的任务&#xff0c;需要…

javaee jsp页面 九大内置对象和四大作用域

九大内置对象四大域 一、四大域 域对象的作用:保存数据,获取数据,共享数据 作用域从小到大为&#xff1a;PageContext&#xff08;jsp页面&#xff09;&#xff0c;ServletRequest&#xff08;一次请求&#xff09;&#xff0c;HttpSession&#xff08;一次会话&#xff09;&am…

如何使用MATLAB软件完成生态碳汇涡度相关监测与通量数据分析

MATLAB MATLAB是美国MathWorks公司出品的商业数学软件&#xff0c;用于数据分析、无线通信、深度学习、图像处理与计算机视觉、信号处理、量化金融与风险管理、机器人&#xff0c;控制系统等领域。 [1] MATLAB是matrix&laboratory两个词的组合&#xff0c;意为矩阵工厂&a…

postgresql导入导出数据库的一些问题

新建一个数据库 别忘了添加空间数据的扩展 备份之前的数据库 注意一定要自定义表&#xff0c;去掉 spatial_ref_sys &#xff0c;要不然需要先drop在创建&#xff0c;可能会报错。 一般不会去导函数&#xff0c;如果有个别自己创建的函数可以手动复制一下&#xff0c;全部导的话…

Centos 7 使用国内镜像源更新内核

内核选择参考 此博文 &#xff1a;https://blog.csdn.net/alwaysbefine/article/details/108931626 elrepo官网介绍的内核升级方式为&#xff1a; 一、按文档执行引入 elrepo库&#xff1b; # 1、引入公钥 rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org# 2、安…

微服务系列文章 之 Nginx服务状态监控的方法

在Nginx的插件模块中有一个模块stub_status可以监控Nginx的一些状态信息&#xff0c;默认安装可能没有这个模块&#xff0c;手动编译的时候加一下即可。 1. 模块安装 先使用命令查看是否已经安装这个模块&#xff1a; [rootihxb123Z nginx]# ./nginx -V (V大写会显示版本号和…

sql练习题

DQL练习1-学生表 创建如下学生表 create table student( id int, name varchar(20), gender varchar(20), chinese int, math int, english int ); insert into student values (1,张明,男,89,78,90), (2,李进,男…

系统学习Linux-SSH远程服务(二)

概念 安全外壳协议&#xff0c;提供安全可靠的远程连接 特点 ssh是工作在传输层和应用层的协议 ssh提供了一组管理命令 ssh 远程登陆 scp 远程拷贝 sftp 远程上传下载 ssh-copy-id ssh keygen 生成 提供了多种身份验证机制 身份验证机制 密码验证 需要提供密码 密…

pyGPlates + GPlately + PlateTectonicTools——深时时空数据分析

pyGPlates GPlately PlateTectonicTools——深时时空数据分析 摘要介绍准备example 1&#xff1a;通过DataServer对象从EarthByte serves上获取板块模型 板块重建 资料来源备注&#xff1a; gplately API文档 摘要 GPlates作为桌面图形用户界面应用&#xff0c;可用于深时地…

计算机网络 day6 arp病毒 - ICMP协议 - ping命令 - Linux手工配置IP地址

目录 arp协议 arp病毒\欺骗 arp病毒的运行原理 arp病毒产生的后果&#xff1a; 解决方法&#xff1a; ICMP协议 ICMP用在哪里&#xff1f; ICMP协议数据的封装过程 ​编辑 为什么icmp协议封装好数据后&#xff0c;还要加一个ip包头&#xff0c;再使用ip协议再次进…