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

1

6

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.
Carlie answered 25/9, 2017 at 16:7 Comment(0)
C
10

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?

Carlie answered 12/12, 2017 at 18:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.