我正尝试使用目录为foo/bar
的目录/work/a
中的Composer开发一个PHP库(称为composer.json
):
{
"name": "foo/bar",
"require": {
"php": ">=7.2"
}
}
/work/a
是一个git项目,我在分支mybranch
我正在尝试使用目录testing/foobar
中包含work/b
内容的Composer在本地另一个项目(称为composer.json
)中使用此lib:
{
"name": "testing/foobar",
"type": "project",
"repositories": [
{
"type": "vcs",
"url": "/work/a"
}
],
"require": {
"php": "^7.4",
"foo/bar": "mybranch"
}
}
在$ composer install
中运行/work/b
时收到错误消息:
[UnexpectedValueException]
Could not parse version constraint mybranch: Invalid version string "mybranch"
答案 0 :(得分:5)
您必须在分支名称前加上dev-
,因此分支名称必须为dev-mybranch
。
Loading a package from a VCS repository
...
在composer.json
中,应在自定义分支名称前加上"dev-"
。
...
也请检查此问题{/ 3}。
dev-
前缀,并将其添加到/work/b
项目中:{
"name": "testing/foobar",
"type": "project",
"repositories": [
{
"type": "vcs",
"url": "/work/a"
}
],
"require": {
"php": "^7.4",
"foo/bar": "dev-mybranch"
}
}
composer install
:❯ composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing foo/bar (dev-mybranch 85c97b7): Cloning 85c97b7b23 from cache
Writing lock file
Generating autoload files