layout | group | subgroup | title | menu_title | menu_order | version | github_link | redirect_from | ||
---|---|---|---|---|---|---|---|---|---|---|
default |
extension-dev-guide |
03_Build |
The composer.json file |
The composer.json file |
1000 |
2.0 |
extension-dev-guide/build/composer-integration.md |
|
Magento 2 uses Composer{:target="_blank"}, a PHP 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 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 extension if installed using Composer (including from Packagist{:target="_blank"}, Magento Marketplace{: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.
Magento uses the composer binary in the <Magento root>/vendor/composer
directory instead of a globally installed composer.
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
{:target="_blank"} to set up the project structure.
The installation instructions for system integrators use the Magento CE and 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-community-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 module 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 theme 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{: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, 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{: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{: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 such as Magento CE or Magento EE
: suffix
is a unique identifier for extensions of that type.
{% include php-dev/component-versioning.md %}