Composer: require-dev is not overriding require in composer.json

Created on 29 Feb 2016  ·  3Comments  ·  Source: composer/composer

Hi,
I was trying to use the require-dev on my local environment and on my UAT environment, but every time I use "composer update" I get errors if I have some packets in require-dev overriding require packages.
Here is an example of my composer.json:

... "require": {
        "php": ">=5.5.0",
        "wp/wordpress": "4.4.2",
        "wp/amazon-web-services": "0.2.2",
        "wp/members": "^1.0.2",
        "wp/nextgen-gallery-custom-fields": "^1.2.4",
        "wp/wpml-string-translation": "^2.2.6",
        "wp/sitepress-multilingual-cms": "^3.2.7",
        "wp/wpml-translation-management": "^2.0.5"
},
    "require-dev": {
        "wp/wp-functional-tests": "^1.0.0",
    "wp/sitepress-multilingual-cms": "dev-testing-3.3.6",
    "wp/wpml-string-translation": "dev-testing-2.3.6.1",
        "wp/wpml-translation-management": "dev-testing-2.1.5"
}, ...

when I run a composer update I get this error:

Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Updating wp/wpml-string-translation (2.3.2 => dev-testing-2.3.6.1 ddc3c6b)
    Checking out ddc3c6b3923fe47deda4d8d....

  - Updating wp/sitepress-multilingual-cms (3.3.1 => dev-testing-3.3.6 164cab6)
    Checking out 164cab6c3c756ba031c58a3....



  [Composer\DependencyResolver\SolverProblemsException]
    Problem 1
      - The requested package wp/wpml-string-translation ^2.2.6 could not be found.
    Problem 2
      - The requested package wp/sitepress-multilingual-cms ^3.2.7 could not be found.
    Problem 3
      - The requested package wp/wpml-translation-management ^2.0.5 could not be found.
  Potential causes:
   - A typo in the package name
   - The package is not available in a stable-enough version according to your minimum-stability setting
     see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
  Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

Am I missing something? Isn't the require-dev supposed to override require plugins? why it's just not finding my stable versions? (that of course find if I'm not using require-dev)

Thanks a lot

Support

Most helpful comment

So what should I do if I want to use continuous integration and build my package on different environment like prod, stage, dev, uat where stage and prod have require stable versions and on uat and dev I want to test different one? should I always do different packages standing alone?
It would be great to use require/require-dev to establish some sort of hierarchy (in the Continuous integration context)

All 3 comments

It's not overriding no, it's merging the two so ifthey don't match that creates problem. Requiring something in both require and require-dev isn't really a supported use case and very likely to result in problems. I would advise you to just pick if a package is needed only for development or not, and then have it listed only once.

So what should I do if I want to use continuous integration and build my package on different environment like prod, stage, dev, uat where stage and prod have require stable versions and on uat and dev I want to test different one? should I always do different packages standing alone?
It would be great to use require/require-dev to establish some sort of hierarchy (in the Continuous integration context)

Your problem is in workflow, not technical - you should adopt a branch based workflow for maintaining different stages of development. Commonly you develop in master, test in version branches like 1.0.x, and release to tags. Git makes that workflow easy by merging issue branches to master, and commits in master back to version branches. CI tools like Travis are prepared for monitoring all branches and new tags for a given repository. As you can have different versions of composer.json in each commit and branch this solves your problem right away.

In the rare remaining cases where you would like to have several different instances of composer.json, for example to test a deployment with all suggested packages installed, you could just have another like composer-with-suggests.json and use the COMPOSER env variable:

COMPOSER=composer-with-suggest.json composer install
Was this page helpful?
0 / 5 - 0 ratings