我的git repo服务器上有两个项目.第一个是我写的图书馆,让我们称之为foo/lib-bar.第二个是使用该库的应用程序foo/app-bar.目前该库处于开发版本,因此composer.json该库的文件如下所示:
{
"name": "foo/lib-bar",
"description": "Bar library",
"version": "1.0.0-dev",
"type": "library",
"require": {
"php": ">=5.4",
"ext-posix": "*"
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序使用此库,因此它包含必要的要求:
{
"name": "foo/app-bar",
"description": "Bar application",
"version": "0.5.0-dev",
"type": "application",
"repositories": [
{
"type": "vcs",
"url": "ssh://user@git.example.com/lib-foo"
}
],
"require-dev": {
"foo/lib-bar": ">=1.0.0-dev",
},
"require": {
"php": ">=5.5.3"
}
}
Run Code Online (Sandbox Code Playgroud)
一切是顺利了这一点:既composer install和composer update按预期运行,安装依赖,我可以看到它在vendor/
现在,文档说明了这一点
require#
Lists packages required by this package. The package will not be installed unless those requirements can be met.
Run Code Online (Sandbox Code Playgroud)
对于导致问题的步骤:
好的,我的库已准备好部署并退出开发阶段.在我的应用程序的生产版本中也恰好需要它.我dev从composer.json我的库文件中删除后缀,提交并推送文件,并准备更新应用程序.
使用应用程序,composer.json我将库依赖项从require-devsection移到require并删除dev后缀(所有内容都是复制粘贴的,所以没有拼写错误 - 我已经检查并再次重新检查):
"require-dev": {},
"require": {
"php": ">=5.5.3",
"foo/lib-bar": ">=1.0.0"
}
Run Code Online (Sandbox Code Playgroud)
现在我跑了composer update,我得到:
$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for foo/lib-bar >=1.0.0 -> satisfiable by foo/lib-bar[dev-master].
- Removal request for foo/lib-bar == 9999999-dev
Run Code Online (Sandbox Code Playgroud)
我以为它没找到新版本,所以我手动删除了旧库:
$ rm composer.lock
$ rm -rf vendor/foo/
Run Code Online (Sandbox Code Playgroud)
并尝试从头开始安装
$ composer install
Run Code Online (Sandbox Code Playgroud)
但这次它给了我:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package foo/lib-bar could not be found in any version, there may be a typo in the package name.
Run Code Online (Sandbox Code Playgroud)
所以看起来require-dev确实有效,但require事实并非如此.对这里可能出错的任何建议?
require-dev不是开发依赖的地方。它适用于仅在开发中使用的软件,例如 PHPUnit、Mockery 等,或者适用于本身有用的依赖项,但在这种情况下仅用于开发,例如软件包所涉及的服务的客户端库(在测试场景中提出一些真实的请求)。
所以你的库从一开始就不应该是“require-dev”的。
另一件事是:如果使用适当的分支和标签, Composer 将扣除版本,即存储库中名为“1.0.x”的分支将被检测为所有 1.0 版本的开发分支,并且对此类版本的任何要求都可能是对此分支满意 - 前提是您通过设置允许开发版本"minimum-stability": "dev"(这将允许所有软件的开发版本 - 而不是有意的),或者当您需要"1.0.0@dev"软件版本时。
当前可能会破坏您的作曲家设置的一件事是您明确提到了库composer.json中的一个版本,这是一个开发版本。您删除了该版本指示器吗?您应该删除它,因为如果 Composer 可以从存储库中的标签中检测版本,而不是在composer.json 中明确提及它们,那么生活会更容易。
最后请确保在使用 Git 时使用适当的版本标记提交。d版本require应与 git 标记版本相对应。