2017-09-25 36 views
0

我有以下composer.json文件:如何覆盖由packagist.org上托管的composer.json定义的必需版本?

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

,我想迫使aeris/guzzle-http-mock package使用不同版本的guzzlehttp/guzzle(如5.3.1),但它似乎要求读取来自composer.json文件托管在packagist.org。是否有任何解决方法来覆盖这些要求?

所以不是:

"guzzlehttp/guzzle": "~5.0.0" 

我想设置:

"guzzlehttp/guzzle": "^5.3" 
只改变我的地方 composer.json文件

理想。

目前该命令将显示冲突错误:

$ 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. 

回答

0

有使用replace property一种变通方法,旨在取代定的包,所以其他的包不会下载它。例如:

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

将忽略guzzlehttp/guzzle依赖性,它不会被下载,但是正确的版本需要单独或作为包的一部分而提供。

例如,所需的存储库可以手动加入克隆:

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

另一个想法是使用inline aliases像:

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

,但它不工作无论如何,经过这种方式测试后,但也许有一种方法。


相关GitHub上线:How to replace the 3rd party dependency?