0
votes

I have some problem by using Composer to load a custom library from another custom library


I have 2 custom libraries called "ia/audit_trail" and "ia/flash". And "ia/audit_trail" needs "ia/flash" to work.

audit_trail : https://github.com/pierrererot/audit_trail

flash : https://github.com/pierrererot/flash

So, I have the require property set for calling another one. Nothing special, BUT, when I run a simple composer update -vvv in my main project, I got this error :

Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for ia/audit_trail_component ~1.0.0 -> satisfiable by ia/audit_trail_component[1.0.0].
- ia/audit_trail_component 1.0.0 requires ia/flash_component ~1.0.0 -> 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.
- It's a private package and you forgot to add a custom repository to find it

Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems...

BUT, if I put these two librairies directly into my main project (so if one librairy doesn't need another librairy), it works !.


Here is the composer.json of my main project :

{
    "require": {
        "ia/audit_trail_component": "1.0.0"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/pierrererot/audit_trail.git"
        }
    ]
}

All right. So I did require my custom "audit_trail" library. So now, here is the composer.json of my custom "audit_trail" library :

{
    "name": "ia/audit_trail_component",
    "version": "1.0.0",
    "type": "library",
    "require": {
        "ia/flash_component": "1.0.0"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/pierrererot/flash.git"
        }
    ],
    "minimum-stability": "dev"
}

All right. So I did require my custom "flash" library. And then, here is the composer.json of my custom "flash" library :

{
    "name": "ia/flash_component",
    "version": "1.0.0",
    "description": "Flash Component",
    "type": "library",
    "minimum-stability": "dev"
}

As you can see, everything seems ok in my composer files, so I don't understand what I missed.

==> Does anyone have a clue please ?

Before you ask, I precise these things :

  • Both libraries have a "dev" and a "master" branch pushed on their Git repositories

  • Both libraries have a minimum 1.0.0 tag pushed on their Git repositories

1
you have to declare them on packagist.org (which is the registry for composer, ie the database of the public packages) . Putting it on github doesn't make it available for composer until you register it on packagist.Pierre Emmanuel Lallemant
if these are private packages, you have to add another field to indicate the url of the repos.Pierre Emmanuel Lallemant
getcomposer.org/doc/… if you don't register them on packagist, should do the trickPierre Emmanuel Lallemant
Thanks for your answers. But I did add a field to indicate the URL of the repos. Look at the URL properties into both composer.json files.Raken_887
PS : I edited my topic, because it looks like a dependecy issue. I added this paragraph : "BUT, if I put these two librairies directly into my main project (so if one librairy doesn't need another librairy), it works !."Raken_887

1 Answers

2
votes

repositories setting is root-only - Composer will ignore this setting for all dependencies and use only these repositories defined in your main project.

Repositories are only available to the root package and the repositories defined in your dependencies will not be loaded. Read the FAQ entry if you want to learn why.

https://getcomposer.org/doc/05-repositories.md#repository

So you need add all necessary repositories into composer.json of your main project:

"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/pierrererot/audit_trail.git"
    },
    {
        "type": "vcs",
        "url": "https://github.com/pierrererot/flash.git"
    }
],