group | subgroup | title | menu_title | menu_order | redirect_from | ||
---|---|---|---|---|---|---|---|
php-developer-guide |
03_Build |
The composer.json file |
The composer.json file |
1000 |
|
Magento 2 uses Composer{:target="_blank"}, a {% glossarytooltip bf703ab1-ca4b-48f9-b2b7-16a81fd46e02 %}PHP{% endglossarytooltip %} dependency manager, to package components and product editions.
Composer reads a composer.json
file in Magento's root directory to download third-party dependencies listed in the file.
The [Component Manager][1] uses the composer.json
file in an extension's root directory to perform the following actions:
- The Component Manager can update, uninstall, enable, or disable an {% glossarytooltip 55774db9-bf9d-40f3-83db-b10cc5ae3b68 %}extension{% endglossarytooltip %} if installed using Composer (including from [Packagist][2]{:target="_blank"}, [Magento Marketplace][6]{:target="_blank"}, or other source) and it has a
composer.json
file. - The Component Manager can still enable or disable an extension not installed using Composer (e.g. custom code) if it has a
composer.json
file.
We recommend you include composer.json
in your component's root directory even if you do not intend to distribute it to other merchants using Magento.
{: .bs-callout .bs-callout-info }
Magento does not support the [path
][3] repository.
Magento uses the composer binary in the <Magento root>/vendor/composer
directory instead of a globally installed {% glossarytooltip d85e2d0a-221f-4d03-aa43-0cda9f50809e %}composer{% endglossarytooltip %}.
Keep this in mind while customizing, updating, or troubleshooting composer while working with Magento 2.
In Composer, a "project" package is a template used by the [composer create-project
][9]{:target="_blank"} to set up the project structure.
The [installation instructions for system integrators][10] use the {{site.data.var.ce}} and {{site.data.var.ee}} project packages to set up the Magento directory structure.
A "product" package is the actual application pointed to by the composer.json
file after you download and install the project package using composer create-project
.
The following Magento components and product editions use a composer.json
file.
Location: composer.json
Name: magento/magento2ce
Type: project
This is Magento's main composer.json
file which declares dependencies and third-party components.
Other root composer.json
files use this file as a template.
Location: composer.json
Name: magento/project-community-edition
Type: project
Magento system integrators use this composer.json
file to deploy the Magento Community Edition product and its dependencies.
Location: composer.json
Name: magento/product-enterprise-edition
Type: metapackage
Magento system integrators use this composer.json
file to deploy the Magento Enterpries Edition product and its dependencies.
Location: lib/internal/Magento/Framework/composer.json
Name: magento/framework
Type: magento2-library
The Magento application uses this composer.json
file for its framework packages.
Locations:
app/code/<vendor-name>/<module-name>/composer.json
vendor/<vendor-name>/<module-name>/composer.json
Name: <vendor-name>/<package-name>
Type: magento2-module
The composer.json
file for a {% glossarytooltip c1e4242b-1f1a-44c3-9d72-1d5b1435e142 %}module{% endglossarytooltip %} extension declares external dependencies that it needs to function.
Locations:
app/design/frontend/<vendor-name>/<theme-name>/composer.json
app/design/adminhtml/<vendor-name>/<theme-name>/composer.json
Name: <vendor-name>/<package-name>
Type: magento2-theme
The composer.json
file for a {% glossarytooltip d2093e4a-2b71-48a3-99b7-b32af7158019 %}theme{% endglossarytooltip %} component contains parent theme dependencies the extension needs to inherit.
Location:
app/i18n/<vendor-name>/<language-code>/composer.json
Name: <vendor-name>/<package-name>
Type: magento2-language
For language packages, you must use the correct [ISO code][4]{:target="_blank"} for the language code in the composer.json
file.
Magento extensions can be any of the following types:
magento2-module
for modulesmagento2-theme
for themesmagento2-language
for language packagesmagento2-component
for general extensions that do not fit any of the other types
The extension type tells the system where to install the directories and files of each extension in the Magento directory structure.
Since the namespace of a Composer package is global within a package repository, e.g. [packagist.org][2], use the following format when naming your package:
<vendor-name>/<package-name>
Using the Composer naming convention helps distinguish packages from different vendors with a low risk of overlapping.
All letters in the vendor name must be in lowercase.
For example, the vendor name format for extensions released by Magento Inc is magento
.
Magento Marketplace uses vendor-name
to match an extension to a vendor during the extension submission process.
If you plan to submit your extension to the [Magento Marketplace][7]{:target="_blank"}, you must use the unique Vendor Name created or assigned to you when you created your marketplace account.
In the composer.json
file, use the value of 'Vendor Name' in your profile for the vendor-name
part of the extension name.
Please see the [Marketplace Documentation][5]{:target="_blank"} for more information about your unique vendor name.
All letters in the package-name
must be in lowercase.
If the name contains more than one word, the Composer specification recommends separating them with dashes.
The convention for Magento package names is the following
magento/<type-prefix>-<suffix>[-<suffix>]...
Where:
: type-prefix
is any of the Magento extension types:
module-
for module extensionstheme-
for theme extensionslanguage-
for language extensionsproduct-
for [metapackages][8] such as {{site.data.var.ce}} or {{site.data.var.ee}}
: suffix
is a unique identifier for extensions of that type.
{% include php-dev/component-versioning.md %}
Next: [Define your configuration files]({{ page.baseurl }}/extension-dev-guide/build/required-configuration-files.html)
[1]: {{ page.baseurl }}/comp-mgr/compman-start.html [2]: https://packagist.org/ [3]: https://getcomposer.org/doc/05-repositories.md#path [4]: https://www.iso.org/iso-639-language-codes.html [5]: http://docs.magento.com/marketplace/user_guide/getting-started-seller.html [6]: https://marketplace.magento.com/ [7]: https://marketplace.magento.com [8]: {{ page.baseurl }}/extension-dev-guide/package/package_module.html#package-metapackage [9]: https://getcomposer.org/doc/03-cli.md#create-project [10]: {{ page.baseurl }}/install-gde/prereq/integrator_install.html