Different Package Version for Development & Production in Composer

Viewed 1970

i am working on multiple composer packages and a application which dose requries all the packages that i develop.

I would like to know how i can have a package with multiple version

  1. stable version for production
  2. development / master version for local development

i tried following config but it din't work

{
  "minimum-stability" : "dev",
  "require"           : {
    "varunsridharan/vsp-framework" : "^1.0",
    "wponion/wponion"              : "^1.0"
  },
  "require-dev"       : {
    "varunsridharan/vsp-framework" : "dev-master",
    "wponion/wponion"              : "dev-development"
  }
}

When i run composer install or composer install --no-dev i get the below output

Loading composer repositories with package information
Updating dependencies


  [Composer\DependencyResolver\SolverProblemsException]
  Problem 1
      - The requested package varunsridharan/vsp-framework ^1.0 exists as varunsridharan/vsp-framework[dev-master] but these are rejected by your constraint.
    Problem 2
      - The requested package wponion/wponion ^1.0 exists as wponion/wponion[dev-development] but these are rejected by your constraint.


install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-author
itative] [--apcu-autoloader] [--ignore-platform-reqs] [--] [<packages>]...

2 Answers

Reason why composer has require and require-dev is to allow developers install packages that will allow them better debugging by using packages that are not suggested to be used in production. By adding a package on require-dev this package will not be required on production.

Ex. If you want to optimize you queries, see if you have any n+1 query problem etc you might want to install php-debugbar that will show you this info, but having this on production might expose your queries and will give sensitive info to bad guys.

Packages included on require will always be installed in development and in production and this is the reason you see the error The requested package xxxxx exists as xxxxx[dev-development] but these are rejected by your constraint.

To have different packages in DEV and PROD you need different composer.json files for each environment like @George said.

You can have one composer.json file that will be the production composer and one composer-dev.json that you can use for development.

On your local environment you will need to set value of COMPOSER env variable to composer-dev.json.

Simple way to do this is by running composer like this: COMPOSER=composer-other.json php composer.phar install

If you want to require a new packages you need to run the command twice, one time normally and one time by adding COMPOSER=composer-other.json before composer, to ensure that the package will be added both in dev and production.

P.S I do not know the reason why you need different packages for development and production, but it is suggested to have the same version of packages in dev and prod as having different versions might bring up bugs

Related