当前位置: 首页 > news >正文

maven的settings.xml

 

  

<settings><localRepository>...</localRepository><servers><server>...</server><servers><mirrors><mirror>...</mirror></mirrors><profiles><profile>...</profile></profiles><activeProfiles><activeProfile>...</activeProfile>  <!-- 与 profile.id 相同 --></activeProfiles>
<settings>

  

<?xml version="1.0" encoding="UTF-8"?><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>D:\develop\maven\maven_repository</localRepository><!-- servers 标签                   --><!-- 作用:配置访问远程仓库所需的认证信息    --><!-- 用途:存储用户名、密码、私钥等安全信息  --><servers><!-- 公司内部私服认证 --><server><id>yl-nexus</id><username>admin</username><password>123456</password></server><!-- 阿里云私服认证 --><!-- ... --></servers><!-- mirrors 标签                   --><!-- 作用:配置仓库镜像,重定向仓库请求     --><!-- 用途:加速下载、替换默认中央仓库       --><mirrors><!-- 镜像私服1 --><mirror><id>nexus</id>    <!-- mirror 的 id 只需要在 mirrors 范围内唯一 --><mirrorOf>*</mirrorOf> <!-- mirror 通过 mirrorOf 属性来匹配要重定向的仓库,不依赖 id 匹配 --><name>yl maven mirror</name><url>http://192.168.80.158:8099/repository/yl/</url></mirror><!-- 镜像私服2 --><mirror><id>alimaven</id><mirrorOf>central</mirrorOf><name>aliyun maven mirror</name><url>https://maven.aliyun.com/repository/public</url></mirror></mirrors><!-- profiles 标签                               --><!-- 作用:定义不同的配置环境                       --><!-- 用途:管理不同环境下的仓库、属性、插件等配置       --><profiles><!-- 私服1环境 --><profile><id>yl</id><!-- 工作原理: 当 Maven 访问 id 为 yl-releases 的 repository 时,会自动查找 servers 中 id 相同的 server 配置,使用其中的认证信息进行身份验证。 --><repositories><!-- 私服1 --><repository><id>yl-nexus</id>    <!-- 与 server 的 id 必须相同,这样才能关联 --><name>ylmaven nexus repository</name><url>http://192.168.80.158:8099/repository/yl/</url><releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></repository></repositories><pluginRepositories><!-- 插件私服1 --><pluginRepository><id>central</id><name>Nexus</name><url>http://192.168.80.158:8099/repository/yl/</url><releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></pluginRepository></pluginRepositories></profile><!-- 公网环境 --><profile><id>public-env</id><repositories><repository><id>aliyun-repo</id><url>https://maven.aliyun.com/repository/public</url></repository></repositories></profile></profiles><!-- activeProfiles 标签      --><!-- 作用:激活指定的 profile    --><!-- 用途:确定当前使用哪个配置环境  --><activeProfiles><activeProfile>yl</activeProfile>  <!-- 与 profile.id 相同 --></activeProfiles></settings><!-- 
各配置元素的作用:server: 存储访问远程仓库的认证信息(用户名、密码)mirror: 重定向仓库请求到镜像仓库profile: 定义不同环境的配置集合repository: 声明项目依赖的仓库地址pluginRepository: 声明插件依赖的仓库地址activeProfile: 指定当前激活的 profileID 关联关系:1. server.id 与 repository.id 必须相同2. server.id 与 pluginRepository.id 必须相同3. mirror.id  只需要在 mirrors  范围内唯一,通过 mirrorOf 属性匹配仓库4. profile.id 只需要在 profiles 范围内唯一,通过 activeProfile 引用工作原理流程:1.Profile 激活: activeProfile 激活对应的 profile2.仓库解析:从激活的 profile 中获取 repository 和 pluginRepository 中声明的仓库3.认证匹配:如果仓库需要认证,根据 repository.id 和 pluginRepository.id 查找对应的 server.id4.仓库匹配:根据 mirrorOf 规则匹配仓库5.请求重定向:将原仓库请求转发到镜像地址6.依赖下载:从镜像仓库下载所需依赖总结:activeProfile -> profile(环境) -> repository/pluginRepository(仓库) -> server(私服仓库认证) -> mirror(具体访问地址)Maven 构建完整工作流程1. 构建启动阶段(1) 执行 mvn package 命令(2) Maven 读取 settings.xml 配置文件(3) 解析并激活 activeProfiles 中指定的 profile2. Profile 激活与合并(1) 根据 activeProfile 激活对应的 profile(2) 将激活的 profile 中的配置与全局配置合并(3) 获取 profile 中定义的 repository 和 pluginRepository 仓库列表3. 依赖解析阶段(1) 解析项目 pom.xml 中声明的依赖(2) 确定每个依赖所需的仓库位置4. 镜像匹配与重定向(1) 检查 mirrors 配置中的 mirrorOf 规则(2) 根据规则将原始仓库请求重定向到镜像地址例如:mirrorOf=central 会将中央仓库请求重定向到镜像5. 仓库认证匹配(1) 根据 repository.id 查找对应的 server 配置(2) 获取访问私有仓库所需的认证信息(用户名、密码)6. 依赖下载(1) 从重定向后的镜像仓库或原始仓库下载依赖(2) 如果是私有仓库,则使用对应的认证信息7. 编译与打包(1) 基于下载的依赖执行编译(2) 运行测试(如果包含 test 阶段)(3) 执行打包操作生成最终产物整个流程中,profile 提供了环境特定的配置,mirror 加速了依赖下载,server 提供了认证支持。
--><!-- 
Maven mirrorOf 规则详解1. 基本规则*: 匹配所有仓库external:*: 匹配所有外部仓库(除了本地仓库)central: 仅匹配中央仓库repo1: 匹配 Maven 1.x 的中央仓库2. 排除规则*,!repo1: 匹配所有仓库,但排除 repo1external:*,!central: 匹配所有外部仓库,但排除中央仓库3. 多仓库匹配central,public: 匹配 central 和 public 两个仓库repo1,repo2,repo3: 匹配多个指定仓库4. 特殊规则external:http:*: 匹配所有使用 HTTP 协议的外部仓库*>external:*: 复杂的排除和包含组合5. 工作原理Maven 根据 mirrorOf 的值来决定哪些仓库请求需要被重定向当多个 mirror 配置匹配同一个仓库时,按照配置顺序优先匹配第一个匹配成功后,原始仓库的 URL 会被替换为 mirror 的 url--><!-- 
Maven 依赖仓库定位机制:
(1) 依赖的 groupId、artifactId、version 定位例如:com.alibaba:fastjson:1.2.78 → /com/alibaba/fastjson/1.2.78/fastjson-1.2.78.jar
(2) 仓库搜索顺序本地仓库:首先检查 ~/.m2/repository/配置的远程仓库:按照 settings.xml 和 pom.xml 中定义的仓库顺序搜索
(3) 仓库继承机制项目 pom.xml 中定义的 repositories父 pom.xml 中定义的 repositoriessettings.xml 中 profile 定义的 repositories默认的中央仓库 central镜像重定向触发 : 当 Maven 确定要在某个仓库(如 central)下载依赖时,才会应用 mirrorOf 规则进行重定向。
-->

 

http://www.gsyq.cn/news/49184.html

相关文章:

  • 2025年土陶泡菜坛直销厂家权威推荐榜单:陶瓷酒瓶/土陶酒坛/储酒坛源头厂家精选
  • 信创浪潮下,国产DevOps平台如何乘风破浪?
  • 双赢思维
  • Windows 11 系统对磁盘进行分区保姆级教程
  • 2025年知名的节能加热圈厂家最新TOP排行榜
  • 2025年热门的废水处理液体分离设备TOP实力厂家推荐榜
  • 【URP】Unity[后处理]晕影Vignette
  • 2025年知名的酶制剂浓缩设备最新TOP厂家排名
  • 2025年比较好的板材超声波探伤厂家最新推荐排行榜
  • 从 .NET Core1.0 到 .NET 10:.NET + C# 演进全景
  • 再见 Postman!一款开源免费的全能 API 客户端工具!
  • 2025安全立网销售厂家排行
  • 2025年瑜伽垫源头厂家推荐榜
  • 2025年口碑好的通风设备管道TOP品牌厂家排行榜
  • 2025年企业微信服务商综合排名TOP10:数字化转型首选指南
  • 字节串和字符串对比
  • 双北斗卫星时间同步系统:安徽京准助力基础网络建设准绳
  • 2025年11月国内可平滑替换VMware Workspace ONE产品榜:权威对比
  • DotMemory系列:1. 终结队列积压引发的内存暴涨分析
  • 2025年临时办公空间平台推荐榜单
  • 微服务/分布式 基础面试题
  • 2025年联合办公工位渠道口碑推荐榜
  • 很多人问:我能做独立开发吗?
  • 2025年超融合软件推荐排行
  • 2025年11月工程管理软件推荐榜单:斗栱云领衔五强对比评测
  • debian-灵芯派
  • 2025年低频变压器供应商口碑排行榜单
  • 2025年11月中国品质好的红枣供应商
  • 2025年知小有平台深度解析:总平台+多实战联动的创收生态拆解
  • 2025年知小有平台深度解析:副业创收生态的闭环逻辑与风险边界