Hard Dependency vs Soft Dependency in Magento 2

dependencymagento2module

In Magento 2 (any stable version) you can run this command bin/magento info:dependencies:show-modules and you will get a csv file in the root of your application called modules-dependencies.csv with all the module dependencies that looks like this:

enter image description here

What is a Hard dependency and what is a Soft dependency? An example of each would help.

Best Answer

There are three different dependency parsers (implementations of Magento\Setup\Module\Dependency\ParserInterface):

  • code: looks for classes used in code
  • config/xml: looks for dependencies in module declaration
  • composer/json: looks for dependencies in composer.json

The only one that makes a distinction between hard and soft dependencies is the composer parser (see: Magento\Setup\Module\Dependency\Parser\Composer\Json::extractDependencies())

A soft dependency is a package, listed in "suggest", a hard dependency a package in "require".

The default dependency type is hard, that means dependencies found by the other parsers are always hard (see Magento\Setup\Module\Dependency\Report\Dependency\Data\Dependency::__construct()).

Related Topic