composer/composer — Issue #403: SolverProblemsException when defining custom repositories
Author: maoueh
Created: 2012-03-07 14:04:24+00:00
State: open

Here the story. I needed FOSFacebookBundle in my application but it doesn't have a `composer.json` file right now. So, I decided to clone the repo and add my own version of the package to [packagist.org](http://packagist.org).

Just before starting the description of the issue, here some folder and definitions I will use to be clear. The bundle/library package is located in a folder `C:\Dev\FOSFacebookBundle`. I will call this the library. My application is at `C:\Dev\Application` and I will call this the application.

So, I went ahead with the creation of the `composer.json` file for the library. Since the library requires facebook php sdk, I decided to put it in the `repositories` section of my `composer.json` file. But everytime I tried to install the dependencies from my application, it was failing with a `SolverProblemsException`. I tried a lot of diffrerent configurations to make it work but did not succeed. I searched on [packagist.org](http://packagist.org) for a package similar to my needs and found [knplabs/knp-zend-cache-bundle](http://packagist.org/packages/knplabs/knp-zend-cache-bundle) which also defines custom repositories. It was also failing with the same error when I tried to install dependencies for it.

After some investigation, it is like custom repositories defined in a library sent to [packagist.org](http://packagist.org) are not taken into account when install dependencies for an application. Here some steps to reproduce the problem and a workaround for the moment.

The library `composer.json` file looks like this:

{
"name": "maoueh/fos-facebook-bundle",
"type": "library",
"description": "Do NOT use it yet, this package has an issue right now",
"require": {
"facebook/facebook-php-sdk": "3.1.1"
},
"repositories": {
"facebook/facebook-php-sdk": {
"type": "package",
"package": {
"name": "facebook/facebook-php-sdk",
"version": "3.1.1",
"dist": {
"url": "https://github.com/facebook/facebook-php-sdk/zipball/v3.1.1",
"type": "zip"
}
}
}
}
}

This file is located at `C:\Dev\FOSFacebookBundle`. If I go to this directory and run `php composer.phar install --dry-run`, it says:

> Installing dependencies
Installing facebook/facebook-php-sdk (3.1.1)

Now, I push this changes to my repo, went to [packagist.org](http://packagist.org) and force package update. Then, in my application folder, I put this `composer.json`:

{
"name": "maoueh/acme-bundle",
"require": {
"maoueh/fos-facebook-bundle": "dev-master"
}
}

Now, if I go to `C:\Dev\Application` and do `php composer.phar install --dry-run`, the exception is raised:

> Installing dependencies
[Composer\DependencyResolver\SolverProblemsException]
[Job(cmd=install, target=maoueh/fos-facebook-bundle, packages=[maoueh/fos-facebook-bundle-9999999-dev]), ]

A workaround to this problem is to define the custom repository directly in the application `composer.json` file. So, if I change my application `composer.json` file to:

{
"name": "maoueh/acme-bundle",
"require": {
"maoueh/fos-facebook-bundle": "dev-master"
},
"repositories": {
"facebook/facebook-php-sdk": {
"type": "package",
"package": {
"name": "facebook/facebook-php-sdk",
"version": "3.1.1",
"dist": {
"url": "https://github.com/facebook/facebook-php-sdk/zipball/v3.1.1",
"type": "zip"
}
}
}
}
}

Composer is now able to find the missing package as you can see with the output result of `php composer.phar install --dry-run`:

>Installing dependencies
Installing facebook/facebook-php-sdk (3.1.1)
Installing maoueh/fos-facebook-bundle (dev-master)

This is a long description but with this, it should be possible to reproduce the problem fairly easily. You can see my packagist package at [maoueh/fos-facebook-bundle](http://packagist.org/packages/maoueh/fos-facebook-bundle).

I'm on Windows 7, PHP 5.3.8 and composer version 91411a3.

If you need more info, don't hesitate to ping me.

Regards and keep up with the good work,
Matt