需求和需求之间的区别是什么?(复制)

时间:2021-05-12 13:20:13

This question already has an answer here:

这个问题已经有了答案:

I'm new to the composer and I would like to know the difference between require and require-dev. The composer website doesn't offer a good explanation the difference between these two.

我对作曲家是新手,我想知道需求和需求之间的区别。作曲家网站并没有很好地解释这两者之间的区别。

The part that I don't get is Lists packages required for developing this package, or running tests, etc. from Composer Official Docs.

我没有得到的部分是列出开发这个包所需的包,或者运行测试,等等,从Composer官方文档。

3 个解决方案

#1


178  

The require-dev packages are packages that aren't necessary for your project to work and shouldn't be included in the production version of your project.

require-dev包是项目工作所必需的包,不应该包含在项目的生产版本中。

Typically, these are packages such as phpunit/phpunit that you would only use during development.

通常,这些包是您在开发过程中只使用的phpunit/phpunit。

#2


50  

seems clear to me:

对我是很清楚的:

require

需要

Lists packages required by this package. The package will not be installed unless those requirements can be met.

列出此包所需的包。除非能够满足这些要求,否则不会安装该软件包。

require-dev (root-only)

require-dev(根)

Lists packages required for developing this package (1), or running tests, etc. The dev requirements of the root package only will be installed if install is run with --dev or if update is run without --no-dev.

列出开发这个包(1)或运行测试等所需的包。只有在使用——dev运行安装或不使用——no-dev运行更新时,才会安装根包的开发需求。

http://getcomposer.org/doc/04-schema.md

http://getcomposer.org/doc/04-schema.md


1. the packages used to develop a package

1。用于开发包的包。

#3


32  

The key distinction is that Composer will only install require-dev dependencies for the "root package" – the directory where you run composer install. The documentation describes this as:

关键的区别在于,Composer只会为“根包”(运行Composer install的目录)安装require-dev依赖项。文件描述如下:

The root package is the package defined by the composer.json at the root of your project. It is the main composer.json that defines your project requirements.

根包是由编写器定义的包。json位于项目的根。它是主要的作曲家。定义您的项目需求的json。

…and the require-dev documentation specifies that it is "root-only".

而require-dev文档指定它是“仅存的”。

In practice, this means that a package's require-dev dependencies aren't used if the package is being installed as a dependency for something else (ie it's installed to another project's vendor folder).

在实践中,这意味着如果包被安装为其他东西的依赖项(例如,它被安装到另一个项目的供应商文件夹中),则不会使用包的require-dev依赖项。

So if you have phpunit in the require-dev list for YourProject, and I clone down YourProject and run composer install in the yourproject/ directory, Composer will install phpunit to yourproject/vendor/, because it's likely I'm doing some development on YourProject. As part of doing development I'll probably want to run YourProject's test suite, and to do that I'll need phpunit.

因此,如果您在项目的require-dev列表中有phpunit,我将克隆您的项目并在您的项目/目录中运行composer install, composer就会将phpunit安装到您的项目/供应商/中,因为我可能正在对您的项目进行一些开发。作为开发的一部分,我可能想运行您的项目的测试套件,为此我需要phpunit。

But, if I add YourProject as a dependency of MyProject, installing the myproject package will install the yourproject package as well, but it will not install phpunit.

但是,如果我将您的项目添加为MyProject的依赖项,那么安装MyProject包也会安装YourProject包,但它不会安装phpunit。

You can override this behaviour with the --dev and --no-dev options, but the default behaviour is based on whether the package concerned is the root package.

您可以使用-dev和-no-dev选项覆盖此行为,但默认行为取决于相关包是否是根包。

#1


178  

The require-dev packages are packages that aren't necessary for your project to work and shouldn't be included in the production version of your project.

require-dev包是项目工作所必需的包,不应该包含在项目的生产版本中。

Typically, these are packages such as phpunit/phpunit that you would only use during development.

通常,这些包是您在开发过程中只使用的phpunit/phpunit。

#2


50  

seems clear to me:

对我是很清楚的:

require

需要

Lists packages required by this package. The package will not be installed unless those requirements can be met.

列出此包所需的包。除非能够满足这些要求,否则不会安装该软件包。

require-dev (root-only)

require-dev(根)

Lists packages required for developing this package (1), or running tests, etc. The dev requirements of the root package only will be installed if install is run with --dev or if update is run without --no-dev.

列出开发这个包(1)或运行测试等所需的包。只有在使用——dev运行安装或不使用——no-dev运行更新时,才会安装根包的开发需求。

http://getcomposer.org/doc/04-schema.md

http://getcomposer.org/doc/04-schema.md


1. the packages used to develop a package

1。用于开发包的包。

#3


32  

The key distinction is that Composer will only install require-dev dependencies for the "root package" – the directory where you run composer install. The documentation describes this as:

关键的区别在于,Composer只会为“根包”(运行Composer install的目录)安装require-dev依赖项。文件描述如下:

The root package is the package defined by the composer.json at the root of your project. It is the main composer.json that defines your project requirements.

根包是由编写器定义的包。json位于项目的根。它是主要的作曲家。定义您的项目需求的json。

…and the require-dev documentation specifies that it is "root-only".

而require-dev文档指定它是“仅存的”。

In practice, this means that a package's require-dev dependencies aren't used if the package is being installed as a dependency for something else (ie it's installed to another project's vendor folder).

在实践中,这意味着如果包被安装为其他东西的依赖项(例如,它被安装到另一个项目的供应商文件夹中),则不会使用包的require-dev依赖项。

So if you have phpunit in the require-dev list for YourProject, and I clone down YourProject and run composer install in the yourproject/ directory, Composer will install phpunit to yourproject/vendor/, because it's likely I'm doing some development on YourProject. As part of doing development I'll probably want to run YourProject's test suite, and to do that I'll need phpunit.

因此,如果您在项目的require-dev列表中有phpunit,我将克隆您的项目并在您的项目/目录中运行composer install, composer就会将phpunit安装到您的项目/供应商/中,因为我可能正在对您的项目进行一些开发。作为开发的一部分,我可能想运行您的项目的测试套件,为此我需要phpunit。

But, if I add YourProject as a dependency of MyProject, installing the myproject package will install the yourproject package as well, but it will not install phpunit.

但是,如果我将您的项目添加为MyProject的依赖项,那么安装MyProject包也会安装YourProject包,但它不会安装phpunit。

You can override this behaviour with the --dev and --no-dev options, but the default behaviour is based on whether the package concerned is the root package.

您可以使用-dev和-no-dev选项覆盖此行为,但默认行为取决于相关包是否是根包。