如何让Composer使用私有仓库的laravel-menus分支而非官方仓库?
Composer 私有依赖拉取异常问题
环境信息
- Composer版本:2.4.4
- laravel-menus官方上游仓库:https://github.com/nWidart/laravel-menus.git
- 私有副本仓库地址:git@gitlab.mydomain.com:myteam/laravel-menus.git
项目配置
根项目 myteam/laravel 的 composer.json
"repositories": [ { "type": "vcs", "url": "git@gitlab.mydomain.edu:myteam/laravel-lib.git" } ], "require": { "myteam/laravel-lib": "^1.0" },
依赖库 myteam/laravel-lib 的 composer.json
"repositories": [ { "type": "vcs", "url": "git@gitlab.mydomain.edu:myteam/laravel-menus.git" } ], "require": { "nwidart/laravel-menus": "dev-myteam-fixes" },
问题现象
依赖链为:myteam/laravel → myteam/laravel-lib → nwidart/laravel-menus的dev-myteam-fixes私有分支。但Composer不会读取myteam/laravel-lib中的仓库配置,导致拉取的是官方上游仓库的代码,而非私有分支内容。
解决方法
Composer的核心规则是仅根项目的repositories配置会生效,子依赖的仓库配置会被忽略。要解决这个问题,需要把私有仓库配置移到根项目中:
- 修改根项目 myteam/laravel 的 composer.json,添加私有laravel-menus仓库:
"repositories": [ { "type": "vcs", "url": "git@gitlab.mydomain.edu:myteam/laravel-lib.git" }, { "type": "vcs", "url": "git@gitlab.mydomain.edu:myteam/laravel-menus.git" } ], "require": { "myteam/laravel-lib": "^1.0" },
- 执行Composer更新命令,强制拉取私有分支:
composer update nwidart/laravel-menus --with-all-dependencies
这样Composer就能识别到私有仓库的dev-myteam-fixes分支,拉取正确的代码了。
内容的提问来源于stack exchange,提问作者asdflkadslkfadsfjasdadsfsad
相关产品推荐
相关产品推荐

