Nested dependencies and private repositories with composer

sia*_*one 6 composer-php

At the company I'm currently working we've recently started to move our code into different private repositories so that it's more maintainable and reusable (and also to make it easier to open-source it later).

Every PHP repository is also a Composer package that can be required in our project whenever we need it.

At the moment there's an issue with this approach: every time we need a package that depends on other packages we need to specify those also in the root composer.json.

For example, let's say that the in the root composer.json we need to require two packages company\b and company\c, and that the package company\c needs another package company\d. Then the resulting root composer.json will look like this:

{
    "require": {
        "company/b": "dev-master",
        "company/c": "dev-master",
        "company/d": "dev-master"
    },
    "autoload": {
        "psr-4": {
            "Company\\" : "src\Company"
        }
    },
    "repositories": [
        {
            "type": "vcs",
            "url":  "git@bitbucket.org:company/b.git"
        },
        {
            "type": "vcs",
            "url": "git@bitbucket.org:company/c.git"
        },
        {
            "type": "vcs",
            "url": "git@bitbucket.org:company/d.git"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

Is there a way to avoid specifying nested dependencies in the root composer.json and use the ones specified in the composer.json in every package?

Edit: Everything I stated before is valid only for the private packages. If a package, let's say company\b, needs a public package that can be found on Packagist then that dependency CAN be specified in the company\b composer.json and it will be imported.

Sve*_*ven 6

如您正确发现的那样,只有根软件包才能将存储库元数据添加到已知软件包的集合中。

我建议您看看Satis来创建本地Composer存储库。这仅需要您将此单一存储库添加到所有composer.json软件包的所有文件中,它将用作有关所有私有存储库的可更新知识来源。您不再需要在任何地方添加Git存储库列表。

这样,我就为我们的IT企业成功托管了约120个内部软件包。以此为标志,一旦开始将孤立的任务拆分为一个程序包,您将很快获得更多任务。

另请注意,认真对待版本控制很重要。停止依赖分支机构-为您的软件添加标签,进行发布,使用语义版本控制。如果您不这样做,事情有时会破裂,人们会因为您无法使用或弄乱事情而诅咒您(正确)或Composer(错误)。