Eleandro Duzentos
Eleandro Duzentos

Reputation: 1568

How to require a local package that depends on other local package

A have the following folders, each one containing a project:

PackageA
PackageB
PackageC

PackageA depends on PackageB witch also depends on PackageC, each one is a git repository.

This is the PackageA composer.json:

{
    "name": "packagea/packagea",
    "require": {
         "packageb/packageb": "dev-master"
    }
    "repositories": [
        {
            "type": "vcs",
            "url": "../PackageB"
        }
    ]
}

This is the PackageB composer.json:

{
    "name": "packageb/packageb",
    "require": {
         "packagec/packagec": "dev-master"
    }
    "repositories": [
        {
            "type": "vcs",
            "url": "../PackageC"
        }
    ]
}

And this is the PackageC composer.json:

{
    "name": "packagec/packagec"
}

This is what i get when i try composer update on PackageA folder:

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

Problem 1 - Installation request for packageb/packageb dev-master -> satisfiable by packageb/packageb[dev-master]. - packageb/packageb dev-master requires packagec/packagec dev-master -> no matching package found.

Potential causes: - A typo in the package name - The package is not available in a stable-enough version according to your minimum-stability setting see https://getcomposer.org/doc/04-schema.md#minimum-stability for more details.

But, there's a PackageC dependency specified on PackageB

What i'm doing wrong?

Upvotes: 2

Views: 105

Answers (1)

Marcin Orlowski
Marcin Orlowski

Reputation: 75635

The main trick with private dependencies is that entries composer finds in repositories are not shared across whole tree. So if you have your project, which requires package A from VCS, then your project needs to include proper entry in own composer.json's repositories section. This is pretty obvious, but now imagine said package A requires package B from different private repository. So you add what's needed to package B composer.json's repositories but while i.e. unit tests of that package works fine you still will be failing when trying to include that component in your project, same way you described. It's all because of these dependency sources. The not-so-obvious solution is to include all private repositories in your project's composer.json - even if it is not directly needed or used. In other words, your project's composer.json must include entries for VCS repositories as needed by all packages it includes, package A and package B (and so on). In your case you need to make it looke like that:

{
    "name": "packagea/packagea",
    "require": {
         "packageb/packageb": "dev-master"
    }
    "repositories": [
        {
            "type": "vcs",
            "url": "../PackageB"
        },
        {
            "type": "vcs",
            "url": "../PackageC"
        }
    ]
}

Upvotes: 3

Related Questions