Irreconcilable dependencies in Composer

32 Views Asked by At

I have two composer packages that require different versions of the same dependency. I have found answers like this that help me diagnose the problem, but not how to resolve it.

Package A (amphp/phpunit-util) requires phpunit/phpunit ^9; Package B (homegrown) requires phpunit/phpunit ^11.

I looked for some sort of option on the require command that would allow a package to be installed with the version it needs in a "sandboxed" way so that only Package A would use the old version, while other packages could use the new. I couldn't find anything, and barring autoload magic it seems a reach.

What are my options? Can I load phpunit ^11 but somehow convince Package A that phpunit ^9 is available?

1

There are 1 best solutions below

0
Jerry On

The conflict in the package tree can be resolved by making sure that the divergent versions are always in the require-dev sections of the composer.json for the packages that use them. Then downstream packages will not try to load them.

In this case that makes sense because tests for each package should be scoped to the package itself.