必须显式声明"type": "vcs"且url以.git结尾,repositories须为composer.json顶层数组;认证凭据仅支持~/.composer/auth.json(权限600),包名和版本格式须严格匹配私有库composer.json中定义。

必须显式声明 type: "vcs",且 url 末尾带 .git,否则 Composer 完全静默忽略——不报错、不提示、不拉取。
repositories 必须是顶层数组,不能嵌套在 config 或其他字段里
Composer 只扫描 composer.json 最外层的 repositories 字段。写在 config、scripts、extra 甚至 require 旁边都无效。
- ✅ 正确位置:
"repositories": [{ "type": "vcs", "url": "https://gitlab.example.com/acme/utils.git" }] - ❌ 错误写法:
"config": { "repositories": [...] }或"extra": { "repositories": [...] } - 多个私有库就并列写多个对象,顺序无关,但建议把高频使用的放前面
url 必须是能直接 git clone 的 HTTPS 地址,缺 .git 后缀会报 No valid composer.json was found
GitLab 仓库的 HTTPS URL 必须包含 .git 后缀,且不能是网页地址(比如 https://gitlab.example.com/acme/utils 或 https://gitlab.example.com/acme/utils/-/tree/main)。
- ✅ 可用:
https://gitlab.example.com/acme/utils.git - ❌ 不可用:
https://gitlab.example.com/acme/utils(少.git)、https://gitlab.example.com/acme/utils/-/tree/main(是页面 URL) - 如果用了自定义端口(如
:8080),域名 key 在auth.json中也必须完全一致(见下条)
认证凭据只能走 ~/.composer/auth.json,且字段名和权限错一个字就失败
HTTPS 协议下,Composer 不接受 URL 中硬编码 token(如 https://oauth2:glpat-xxx@gitlab.example.com/...),也不读项目根目录下的 auth.json。
【零售数字化AI化高级专家 / Retail Digital & AI Transformation Expert】 —— 面向零售行业的全栈数字化与AI化转型超级工作台。零基础也能达到世界顶级零售数字化AI化专家水平。 ■ 核心定位:覆盖零售全业态(街边夫妻老婆店→社区超市→区域连锁→全国连锁→全球万店品牌)、全业务链路(供应链与采购→仓储与物流中心→门店运营→收银与支付→电商与全渠道→会员与CRM→财务与人力→品牌与加盟)、全技术栈(POS/ERP/WMS/OMS/CRM/CDP/BI/AI
- ✅ 正确路径(Linux/macOS):
~/.composer/auth.json,权限必须为600:chmod 600 ~/.composer/auth.json - ✅ 正确内容结构:
{"http-basic": {"gitlab.example.com": {"username": "oauth2", "password": "glpat-xxx"}}} - ⚠️ 域名 key 必须和
repositories.url的 host 完全一致:若 url 是https://gitlab.example.com:8080/acme/utils.git,则 key 得写"gitlab.example.com:8080",不能省略端口 - 90% 的
HTTP Basic: Access denied实际不是 token 无效,而是auth.json放错位置、权限不对、或字段拼错(比如写成http_basic或https-basic)
require 的包名必须严格匹配私有库 composer.json 里的 name 字段
Composer 不按 Git 路径匹配,只比对私有库自身 composer.json 中的 name 值,大小写、vendor 段、斜杠都不能差。
- 假设私有库根目录
composer.json写的是:"name": "acme/utils" - ✅ 主项目
require必须写:"acme/utils": "dev-main" - ❌ 这些都不行:
"Acme/utils"(大小写)、"acme-utils"(连字符)、"utils"(缺 vendor)、"acme/utils": "main"(漏dev-前缀) - 分支版本必须加
dev-前缀;标签版本可直接写v1.0或1.0.0
最容易被忽略的是 auth.json 的路径和权限——它不报错,只是彻底跳过认证;还有就是 url 少了 .git 后缀,错误信息却指向 composer.json 不存在,容易误判成仓库本身问题。










