为什么composer安装--no-dev不起作用?

时间:2017-02-21 18:31:37

标签: php composer-php

我正在开发一个包含常规依赖项和一个dev依赖项的包库。 Composer recommends to not include the composer.lock file for libraries,所以这里是composer.json

{
    "name": "myself/mypackage",
    "require": {
        "php": ">=5.6",
        "nesbot/carbon": "~1.20"
    },
    "require-dev": {
        "phpunit/phpunit": "^6.0"
    }
}

我希望这与运行PHP 5.6的应用程序兼容,我希望使用最新的PHPUnit测试工具来开发它,这需要PHP 7。

在travis持续集成测试服务器上,我有一个构建矩阵,它在PHP上运行PHPUnit测试> 7和一个linting脚本:

composer install
./lint-php.bash
phpunit

和PHP< 7,简单lint源代码:

composer install --no-dev
./lint-php.bash

但是,它失败了,因为它忽略了--no-dev标志并尝试安装dev依赖项。

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - phpunit/phpunit 6.0.7 requires php ^7.0 -> your PHP version (5.6.5) does not satisfy that requirement.
    - phpunit/phpunit 6.0.6 requires php ^7.0 -> your PHP version (5.6.5) does not satisfy that requirement.
    - phpunit/phpunit 6.0.5 requires php ^7.0 -> your PHP version (5.6.5) does not satisfy that requirement.
    - phpunit/phpunit 6.0.4 requires php ^7.0 -> your PHP version (5.6.5) does not satisfy that requirement.
    - phpunit/phpunit 6.0.3 requires php ^7.0 -> your PHP version (5.6.5) does not satisfy that requirement.
    - phpunit/phpunit 6.0.2 requires php ^7.0 -> your PHP version (5.6.5) does not satisfy that requirement.
    - phpunit/phpunit 6.0.1 requires php ^7.0 -> your PHP version (5.6.5) does not satisfy that requirement.
    - phpunit/phpunit 6.0.0 requires php ^7.0 -> your PHP version (5.6.5) does not satisfy that requirement.
    - Installation request for phpunit/phpunit ^6.0 -> satisfiable by phpunit/phpunit[6.0.0, 6.0.1, 6.0.2, 6.0.3, 6.0.4, 6.0.5, 6.0.6, 6.0.7].

为什么忽略--no-dev标志?我只是想让它安装我的常规依赖项并忽略require-dev部分。

1 个答案:

答案 0 :(得分:6)

尽管有recommendation,但这是因为您没有composer.lock个文件,实际上是a requested feature

首先,它尝试解析所有依赖项。如果失败,则中止。接下来,它运行实际安装,并在那时忽略dev依赖项。你的问题是它无法通过解决的第一步。所以它并不是忽略了--no-dev旗帜,它只是从来没有这么做过。

选项1

如果你包含一个composer.lock文件,那么它会跳过依赖项解析并直接进入安装,此时它会跳过dev依赖项。

选项2

由于您不包含库,而是包含可执行工具,因此您可以完全将其从作曲家中拉出来并使用{{3},而不是与之后可能包含的其他开发工具之间的潜在依赖冲突进行对抗。 }。