Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolving Dependency Hell with Composer

Tags:

composer-php

This is the scenario.

You have package A and package B in your composer.json (your app depends on this 2 packages).

Both package A and B depend on package C, but on different versions. Say A depend on C v2.1, and B depends on C v2.2.

And you get version conflicts.

Both A, B and C are third party packages.

How to resolve this?

like image 606
umpirsky Avatar asked Sep 29 '12 22:09

umpirsky


People also ask

What is the solution for dependency hell?

A very common solution to this problem is to have a standardized numbering system, wherein software uses a specific number for each version (aka major version), and also a subnumber for each revision (aka minor version), e.g.: 10. 1, or 5.

How do I remove composer dependency?

Now just open the composer. json file and delete the dependency which you want to remove. Now we just need to run the composer update command once more and it will remove all the phpunit dependencies which we don't want as shown below: Running composer update once again.


1 Answers

This is a hack but will probably let you move forward.

You could overwrite repositories for "A", "B" and "C" packages and make that "A" and "B" rely on the same version of "C" (actually, might be that it's enough to overwrite repositories for "A" and "B" only).

This should work as long as both "A" and "B" can work with the latest version of "C" (so probably a maintainer didn't update the package version). If it's the case I'd also consider sending a pull request to the project which has an older version of a dependency.

like image 60
Jakub Zalas Avatar answered Sep 27 '22 20:09

Jakub Zalas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!