【问题标题】:composer custom repository package can't pull dependency作曲家自定义存储库包无法提取依赖项
【发布时间】:2016-01-15 16:33:24
【问题描述】:

在作曲家遇到问题。我有一个主要项目,我正在处理我构建的一些小型库,我希望在我的项目之间更轻松地共享这些库。它们还远未准备好发布,所以我不想将它们添加到 packagist,但是当我需要 1 需要另一个时,除非我在我的主 composer.json 上广告该自定义存储库,否则它将出错

另外,第三级需求无法解析 packagegist 库

Your requirements could not be resolved to an installable set of packages.
 Problem 1
   - ethereal/simpleCache dev-master requires predis/predis ^1.1@dev -> no matching package found.
   - ethereal/simpleCache dev-master requires predis/predis ^1.1@dev -> no matching package found.
    - Installation request for ethereal/simplecache dev-master -> satisfiable by ethereal/simpleCache[dev-master].

主项目composer.json:

{
"name": "ethereal/SimpleTable",
"type": "project",
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/mathus13/SimpleConfig.git"
    }
],
"require": {
    "php": ">=5.3.9",
    "doctrine/dbal": "^2.6@dev",
    "ethereal/SimpleConfig": "dev-master"
},
"require-dev": {
    "phpunit/phpunit": "~4.8"
},
"autoload": {
    "psr-4": {
        "Ethereal\\": "lib"
    }
}
}

配置库:在 SimpleTable 中运行 composer update 时,除非 SimpleTable 明确要求,否则不会包含 Simple Cache。

{
"name": "ethereal/SimpleConfig",
"type": "project",
"version": "0.0.1",
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/mathus13/SimpleCache.git"
    }
],
"require": {
    "php": ">=5.3.9",
    "ethereal/SimpleCache": "dev-master"
},
"require-dev": {
    "phpunit/phpunit": "~4.8"
},
"autoload": {
    "psr-4": {
        "Ethereal\\": "lib"
    }
}
}

缓存库:在 SimpleTable 中运行 composer update 时,predis 无法解析。

{
"name": "ethereal/simpleCache",
"type": "project",
"version": "0.0.1",
"require": {
    "predis/predis": "^1.1@dev",
    "php": ">=5.3.9"
},
"require-dev": {
    "phpunit/phpunit": "~4.8"
},
"autoload": {
    "psr-4": {
        "Ethereal\\": "lib"
    }
}
}

【问题讨论】:

    标签: php git composer-php


    【解决方案1】:

    ethereal/SimpleTable 依赖于ethereal/SimpleConfig 的开发稳定性,它依赖于ethereal/SimpleCache 的开发稳定性,它依赖于predis/predis 的开发稳定性(1.1 版尚未发布)。

    包含在主包中的包不能定义任何稳定性,唯一允许的稳定性是主包中的那个。默认情况下这是“稳定的”。

    您通过依赖“dev-master” for SimpleConfig”从该规则中做出了一个例外,但这不是继承的。

    您有多种解决方案:

    1. 标记您的软件。标签声明它比“开发”更稳定,通常最好只在生产中使用标签软件。
    2. 在主包中包含您自己需要的所有包,即使它们不直接使用。这将为它们添加一般稳定性的异常,并允许 Composer 解决任何子依赖项。
    3. 您可以将"minimum-stability":"dev" 添加到主composer.json,但这也将允许从分支安装所有其他软件包。然而,使用分支是一件非常糟糕的事情,因为你不能轻易地回到你更新之前工作的版本——分支指针只会向前移动。只有标签会永远指向同一个软件。
    4. 添加"prefer-stable":true" 是解决 3 引入的问题的某种解决方法,这些软件包已在稳定版本中可用。但是,您仍然会遇到无法返回到您自己的包的早期版本的问题,因为您使用的是分支。

    如果您仍在开发这些软件包,可能需要依赖分支。但是,一个好的包将能够独立开发和测试,除了接口定义(将用于模拟所有内容)之外几乎没有任何外部代码存在,因此将所有代码放在一个混合的 repos 中,通常签出分支是对编写未完全分离的代码的邀请。

    如果这些包中的任何一个已经完成(我会说“足够好”),请标记它并依赖该版本而不是分支。如果您发现错误或想要添加新功能,您可以随时发布新版本。

    【讨论】:

    • 感谢您的深入解释。很有帮助!
    猜你喜欢
    • 2014-10-17
    • 2014-03-10
    • 2015-09-20
    • 2018-12-23
    • 2019-12-02
    • 2019-11-19
    • 2013-04-20
    • 1970-01-01
    • 2016-08-13
    相关资源
    最近更新 更多