How to let composer automatically resolve conflicts that are not real conflicts?

Viewed 1116

I'm regularly told by composer that it can't install some kind of package, because it(s dependencies) conflict with something that I already have installed. Often I can't make heads or tails of the conflict, but when it happened again today I looked into it and I saw that there was no real conflict at all.

I wanted to install a package and composer said that the package I wanted depends on doctrine/inflector at version 1.4 or higher, but that I already have doctrine/inflector installed and locked at 1.3.1.

I looked into it, and I never required doctrine/inflector explicitly. So it's not a direct dependency of my app, but instead it was installed as a dependency of two of my dependencies. Those two dependencies said they needed doctrine/inflector at versions ^1.2 and ^1.0 respectively. (I found that information in my composer.lock file.)

So now I don't see why composer is making a fuss. Yes composer chose to install doctrine/inflector at 1.3.1 in the past to meet the requirements, but there should be no conflict whatsoever if composer just updates the 1.3.1 version it installed in the past to 1.4.1. But it doesn't do that and instead complains about a conflict.

I now solved the conflict manually by running these commands:

$ composer require doctrine/inflector:1.4.1
$ composer require illuminate/support
$ composer remove doctrine/inflector

I used doctrine remove, because I don't want to have doctrine/inflector in my composer.json.

So sure, this worked, but is there a way to configure composer such that it tries to solve these conflicts on its own? Because I'm sure there are more complicated scenarios where I wouldn't be able to figure out what to do, but composer possibly could if it would just try.

I did some searching on this site and found that composer update could've helped me maybe, but then I'm still curious to know if there's a better alternative. You see I'm looking for a method where I don't need to know which packages need updating (and where I don't need to necessarily update all my packages either).

2 Answers

You can achieve with composer require this using these flags:

$ composer require --help | grep update-with
      --update-with-dependencies      Allows inherited dependencies to be updated, except those that are root requirements.
      --update-with-all-dependencies  Allows all inherited dependencies to be updated, including those that are root requirements.

Got exactly the same problem. This seems to be a bad behavior of composer 1.

Switching to composer 2 solves the issue, the option --update-with-all-dependencies (-W) do it's job !

Otherwise, with composer 1 the only solution seems to be the one you did : update manually dependencies, sub-dependencies, sub-sub-... and remove them in composer.json at the end.

Related