cocoapods-local-override
在不修改 Podfile 的前提下,将指定 pod 从远程依赖切换为本地路径(或替换版本号/branch)。
安装
cd Business/Tools/cocoapods-local-override
gem build cocoapods-local-override.gemspec
gem install --local cocoapods-local-override-*.gem
验证安装:
pod plugins installed | grep local-override
使用
1. 创建配置文件
插件会在首次 pod install 时自动从模板 Podfile.local.example 创建 Podfile.local,无需手动操作。
如需手动创建:
cp Tools/cocoapods-local-override/Podfile.local.example Podfile.local
2. 编辑 Podfile.local
local_pods:
BBreachOrder: ../BusinessLayer/BBreachOrder
BMediator: ../CoreLayer/BMediator
BaseConfiguration: ../CoreLayer/BaseConfiguration
BaseFoundation: ../../BasicLayer/BaseFoundation
replace_versions:
SDWebImage: 1.2.3
replace_branches:
DeliverGoods: develop-9.6.2
3. 执行 pod install
pod install
插件自动生效,输出示例:
[ LOCAL ] BTransportationReminder → ../BusinessLayer/BTransportationReminder
[ LOCAL ] BBreachOrder → ../BusinessLayer/BBreachOrder
[ LOCAL ] BMediator → ../CoreLayer/BMediator
[ VERSION ] SDWebImage → 1.2.3
[ BRANCH ] DeliverGoods → develop-9.6.2
[ LOCAL ] WNDatePicker (via BTransportationReminder) → ../../BasicLayer/WNDatePicker/
[+] Added Podfile.local to Pods project
4. 恢复远程依赖
注释掉或删除 Podfile.local 中对应的条目,或不创建该文件即可恢复远程依赖。
功能说明
三种覆盖模式
| 配置项 | 作用 | 标签 |
|---|---|---|
local_pods |
将 pod 替换为 :path 指向本地目录 |
[ LOCAL ] |
replace_versions |
覆盖 Podfile 中声明的版本号 | [ VERSION ] |
replace_branches |
修改 :git 声明的 :branch |
[ BRANCH ] |
三种配置按上述优先级依次匹配,命中的第一个生效。路径不存在时黄色警告并回退远程。
传递依赖自动注入
本地 pod 的 podspec 中声明的依赖,如果也在 local_pods 配置中但未在 Podfile 显式声明,插件会自动将其注入为目标依赖,确保整个依赖树使用本地版本。
输出格式:[ LOCAL ] dep_name (via parent) → path
使用 BFS 遍历依赖树,visited set 防循环引用。
Podfile.local 在 Pods 工程可见
每次 pod install 后,插件自动将 Podfile.local 加入 Pods.xcodeproj,排在工程导航栏首位,方便在 Xcode 中直接查看和编辑。
环境变量
| 变量 | 作用 |
|---|---|
COCOAPODS_LOCAL_OVERRIDE_DISABLE=1 |
禁用插件 |
COCOAPODS_LOCAL_OVERRIDE_CONFIG=/path/config.yml |
指定自定义配置文件路径 |