Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override required version defined by composer.json hosted on packagist.org?

I've the following composer.json file:

{
  "require": {
    "guzzlehttp/guzzle": "^5.3"
  },
  "require-dev": {
    "aeris/guzzle-http-mock": ">=1.1.5"
  }
}

where I'd like to force aeris/guzzle-http-mock package to use different version of guzzlehttp/guzzle (such as 5.3.1), however it seems the requirements are read from the composer.json file hosted on packagist.org. Is there any workaround to override these requirements?

So instead of:

"guzzlehttp/guzzle": "~5.0.0"

I'd like to set:

"guzzlehttp/guzzle": "^5.3"

ideally by changing only my local composer.json file.

Currently the command displays the conflict errors:

$ composer install --prefer-source -vvv
Reading ./composer.json
Loading config file ./composer.json
...
Reading ~/.composer/cache/repo/https---packagist.org/provider-aeris$guzzle-http-mock.json from cache
Resolving dependencies through SAT
Dependency resolution completed in 0.000 seconds
Reading ~/.composer/cache/repo/https---packagist.org/provider-guzzlehttp$guzzle.json from cache
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for aeris/guzzle-http-mock >=1.1.5 -> satisfiable by aeris/guzzle-http-mock[1.1.5].
    - aeris/guzzle-http-mock 1.1.5 requires guzzlehttp/guzzle ~5.0.0 -> satisfiable by guzzlehttp/guzzle[5.0.0, 5.0.1, 5.0.2, 5.0.3] but these conflict with your requirements or minimum-stability.
like image 361
kenorb Avatar asked Mar 08 '23 23:03

kenorb


1 Answers

There is a workaround by using replace property which aims to replace given package, so other packages won't download it. For example:

{
  "require": {
    "aeris/guzzle-http-mock": ">=1.1.5"
  },
  "replace": {
    "guzzlehttp/guzzle": "~5.0.0"
  },
  "minimum-stability": "dev",
  "prefer-stable": true
}

will ignore guzzlehttp/guzzle dependency and it won't be downloaded, however the right version needs to be provided separately or as part of the package.

For example, the required repository can be cloned manually by adding:

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

Another idea is to use inline aliases like:

"guzzlehttp/guzzle": "dev-5.3.0 as 5.0.3"

but it doesn't work as expected anyway after testing this way, but maybe there is a way.


Related GitHub thread: How to replace the 3rd party dependency?

like image 127
kenorb Avatar answered Apr 26 '23 17:04

kenorb