layout | group | subgroup | title | menu_title | menu_order | github_link | redirect_from | ||
---|---|---|---|---|---|---|---|---|---|
default |
extension-dev-guide |
03_Build |
Create composer.json |
Create composer.json |
2 |
extension-dev-guide/build/composer-integration.md |
|
##{{page.menu_title}}
Composer is a dependency manager for PHP. Magento 2 uses Composer to package components and product editions.
Some third-party components that the Magento system uses might not be present in the code base. Instead, they are listed as dependencies in the root composer.json
file. In addition, the [Component Manager]({{ site.gdeurl }}comp-mgr/compman-start.html) looks for a composer.json
in a component's root directory and can perform actions on the component and its dependencies.
In particular:
- If a component has
composer.json
and the component was installed using Composer (including from packagist, the Magento Marketplace, or other source), the Component Manager can update, uninstall, enable, or disable the component. - If the component has
composer.json
but was not installed using Composer (for example, custom code a developer wrote), Component Manager can still enable or disable the component. - We strongly recommend you include
composer.json
in your component's root directory whether or not you intend to distribute it to other Magento merchants.
Certain Magento components and product editions are represented with composer.json
files.
Type of composer.json | Location | Naming convention | Composer type | Notes |
---|---|---|---|---|
Root | composer.json |
magento/magento2ce |
project |
This is the main composer.json file. Magento uses this file to declare dependencies on third-party components. This file is used as a template for any other root composer.json files |
CE project | composer.json |
magento/project-community-edition |
project |
This file represents the Magento Community Edition project. The package only includes the composer.json, which declares the dependencies on the magento product as well as the class autoloader. This can be used by Magento system integrators to deploy Magento using Composer. |
CE product | composer.json |
magento/product-community-edition |
metapackage |
This file represents Magento Community Edition product. The package only includes composer.json that declares the dependencies on magento components (modules, themes, and so on) and third-party components. This can be used by Magento system integrators to deploy Magento using Composer. |
module | app/code/Magento/<Module>/composer.json |
magento/module-catalog-inventory magento/module-checkout |
magento2-module |
The fully qualified module name, broken down into vendor, with the rest of the words as suffixes. The "module" prefix is mandatory to disambiguate from other types (for example, Magento_Backend module versus Magento/backend theme). |
theme | app/design/<area>/Magento/<theme>/composer.json |
magento/theme-frontend-blank magento/theme-adminhtml-backend |
magento2-theme |
Themes belong to areas, so the area name has to be the first suffix |
language packages | app/i18n/magento/<language>/composer.json |
magento/language-en_gb magento/language-de_de |
magento2-language |
The language identifier must be lowercase. |
Magento framework | lib/internal/Magento/Framework/composer.json |
magento/framework |
n/a | Used only by the framework |
Magento does not currently support the path
repository.
{% highlight XML %} <vendor_name>/<package_name>
{% endhighlight %}
As a result, vendors of different packages are distinguished, and there is a low risk of overlapping (unless different vendors names themselves exactly the same). All letters in the name must be lowercase. Therefore, the format for package names released by Magento Inc is:
{% highlight XML %} magento/*
{% endhighlight %}
The package name is up to the vendor (as long as it is lowercase). If this name is meant to consist of multiple words, the Composer specification recommends separating them with dash. The convention for Magento package names is this:
{% highlight XML %} magento/-[-]...
{% endhighlight %}
Where:
type-prefix
is a type of component in a Magento-specific domain.
suffix
is anything that allows distinguishing/disambiguating the component within that type.
Having an identifier type for each component allows the system to marshal the directories and files of each component to the correct locations, based on the Magento 2 directory structure.
{% include php-dev/component-versioning.md %}
Magento's bin/magento
script uses composer from the vendor/composer
directory in your Magento 2 installation, not your globally installed Composer. Keep this in mind while customizing or updating composer or troubleshooting Composer issues while working with Magento 2.
[Define your configuration files]({{ site.gdeurl }}extension-dev-guide/build/required-configuration-files.html)