You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让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配置会生效,子依赖的仓库配置会被忽略。要解决这个问题,需要把私有仓库配置移到根项目中:

  1. 修改根项目 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"
},
  1. 执行Composer更新命令,强制拉取私有分支:
composer update nwidart/laravel-menus --with-all-dependencies

这样Composer就能识别到私有仓库的dev-myteam-fixes分支,拉取正确的代码了。

内容的提问来源于stack exchange,提问作者asdflkadslkfadsfjasdadsfsad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 03:15:14