如何正确地要求Composer中的特定提交,以便它可用于依赖包? [英] How to correctly require a specific commit in Composer so that it would be available for dependent packages?

查看:737
本文介绍了如何正确地要求Composer中的特定提交,以便它可用于依赖包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个库 foo / foo-lib 其中需要来自GitHub的特定提交:

I have a library foo/foo-lib which requires a specific commit from GitHub:

{
    "name": "foo/foo-lib",
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/KnpLabs/Gaufrette.git"
        }
    ],
    "require": {
        "knplabs/gaufrette": "dev-master#2633721877cae79ad461f3ca06f3f77fb4fce02e"
    }
}

且工作正常:

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)                                 
  - Updating knplabs/gaufrette dev-master (2633721 => 2633721)
    Checking out 2633721877cae79ad461f3ca06f3f77fb4fce02e

Generating autoload files

但是当我在其他项目中需要该库时:

but when I require that library in other project:

{
    "name": "bar/bar-app",
    "repositories": [
        {
            "type": "vcs",
            "url": "ssh://git.example.com/foo-lib"
        }
    ],
    "require-dev": {
        "foo/foo-lib": "dev-master"
    }
}

它会产生依赖性错误:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for foo/foo-lib dev-master -> satisfiable by foo/foo-lib[dev-master].
    - foo/foo-lib dev-master requires knplabs/gaufrette dev-master#2633721877cae79ad461f3ca06f3f77fb4fce02e -> no matching package found.

所以我的问题是:如何正确 require

So my question is: how to correctly require the specific commit from GitHub in my library, so that it would be available in dependent packages?

推荐答案

你必须在我的库中使用GitHub的特定提交明确要求在该哈希处使用Gaufrette库,并在库和应用程序中使用 dev 标志。类似这样的应用程序应该在应用程序中工作 composer.json

You'll have to explicitly require the Gaufrette library at that hash, with a dev flag, in both your library and your application. Something like this should work in the application composer.json:

{
    "name": "bar/bar-app",
    "repositories": [
        {
            "type": "vcs",
            "url": "ssh://git.example.com/foo-lib"
        }
    ],
    "require-dev": {
        "foo/foo-lib": "dev-master",
        "knplabs/gaufrette": "dev-master#2633721877cae79ad461f3ca06f3f77fb4fce02e"
    }
}

文档


如果你的一个依赖关系对一个不稳定的包
有依赖性,你需要明确要求它,以及它的充足
稳定性标志。

If one of your dependencies has a dependency on an unstable package you need to explicitly require it as well, along with its sufficient stability flag.

文档还建议您需要在 bar中包含Gaufrette的存储库/ bar-app Composer文件,但在这种情况下听起来似乎没有必要。我不知道为什么。

The documentation also suggests that you'll need to include the repository for Gaufrette in your bar/bar-app Composer file, though it sounds like this wasn't necessary in this case. I'm not sure why.

这篇关于如何正确地要求Composer中的特定提交,以便它可用于依赖包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆