Extension Dependencies
Extensions can have dependencies on one another, that is, an extension can rely on types and functionality implemented in another extension. The dependent extension then can only function properly if the required extension is available.
Technical Background of Extension Dependencies
In theory, extensions in SAP Commerce are independent pieces of software and also are ignorant of one another. That is, an extension does not know per se that there are other extensions, and neither does it use other extensions' functionality or types.
However, in practical use, you will implement extensions that do rely on other extensions' types and functionality - even if you do not notice that explicitly.
An extension that relies on another extension in any way has a so-called extension dependency. Such an extension dependency occurs if an extension uses, modifies, or extends a type defined in another extension. For example:
-
If you extend a CronJob in your extension, your extension relies on the processing extension.
-
If you use Models, your extension relies on the SAP Commerce core extension.
-
And even if you simply use the Product type, your extension relies on the Platform core extension.
Technically, every extension that uses any SAP Commerce type depends on the core extension because the type system is part of the core extension.
An extension may depend on several other extensions. For example, if your extension allows running imports through Backoffice using a wizard, you have an extension dependency not only on the backoffice extension, but also on the impex extension.
Extensions that depend on another extension have access to sources and resources of its coremodule extension component. For example it means that the myextension extension that depends on maintenanceweb extension can use every class located in its src folder. Classes located in web/src folder are not accessible as they are a part of the webmodule extension component, therefore they are accessible only to the Web application of maintenanceweb extension.
For more information, see Spring Framework in SAP Commerce
Detecting an Extension Dependency
There are two basic situations in which you may explicitly notice extension dependencies:
-
During builds of SAP Commerce, that is, by compile time.
The SAP Commerce build framework builds all extensions in a non-deterministic order. That is, you cannot say for sure in which order all the extensions of SAP Commerce will be built.
-
During SAP Commerce initialization / update, that is, by runtime.
Very much in the same way in which the build order is non-deterministic, the order in which extensions are invoked during SAP Commerce initialization or update is non-deterministic.
An extension dependency is met if the required extension is built or initialized before the dependent extension. In that case, SAP Commerce can find the required types and data, and everything is fine.
However, if an extension has a dependency which is not met, the extension may not function properly. The severity of the extension not functioning properly ranges from errors during sample data creation to build failures.
Depending on which extensions an extension depends on, you may even never notice the dependency. If your extension only depends on very basic extensions such as the processing extension, which is built rather early on, your extension dependency may not become noticable for years of use. However, it is rather common that you end up with complex extension dependencies, and you may run into build failures such as:
[mkdir] Created dir: C:\SAPcommerce\...\ext-print\print\classes
[yjavac] Compiling 298 source files to C:\SAPcommerce\...\ext-print\print\classes
[yjavac] ----------
[yjavac] 1. ERROR in C:\SAPcommerce\...\ext-print\print\gensrc\de\hybris\platform\print
\jalo\GeneratedClassificationAttributePlaceholder.java (at line 20)
[yjavac] import de.hybris.platform.catalog.jalo.classification.ClassAttributeAssignment;
[yjavac] ^^^^^^^^^^^^^^^^^^^^^^^^^^
[yjavac] The import de.hybris.platform.catalog cannot be resolved
[yjavac] ----------
[yjavac] 2. ERROR in C:\SAPcommerce\...\ext-print\print\gensrc\de\hybris\platform\print
\jalo\GeneratedClassificationAttributePlaceholder.java (at line 38)
[yjavac] public ClassAttributeAssignment getClassAttributeAssignment(final SessionContext ctx)
[yjavac] ^^^^^^^^^^^^^^^^^^^^^^^^
[yjavac] ClassAttributeAssignment cannot be resolved to a type
[yjavac] ----------
If you run builds of SAP Commerce using ant all, the SAP Commerce build framework will have the compiled files from other extensions available. An extension dependency may then still exist, but will not be noticeable.
In contrast, if you run SAP Commerce builds using the ant clean all, the build framework will delete the compiled files prior to building extensions. A build failure to unmet extension dependencies is much more likely to occur this way.
Therefore, SAP recommends running builds of SAP Commerce using ant clean all from time to time to increase chances of finding implicit extension dependencies.
Resolving Extension Dependencies
Dependencies to Non-Platform Extensions
The SAP Commerce build framework has a built-in mechanism to handle extension dependencies. Every extension can specify a list of other extensions on which it depends. The build framework resolves this list and abides by it. An extension that specifies an extension dependency will only be built once all the extensions specified in the list have been built.
If you find that your extension has an extension dependency, you can therefore explicitly configure your extension to be built only after all required extensions are built, and thereby resolve the extension dependency.
To configure an extension dependency:
-
Open the extensioninfo.xml file of your extension, located in the extension directory.
-
As a child element of the <extension> element, add any number of <requires-extension> elements, such as:
extensioninfo.xml
<extension name="myextension"> <requires-extension name="voucher" /> <requires-extension name="cms" />
For additional details, refer to Extension Configurations.
Dependencies to Platform Extensions
Extension dependencies to the Platform extensions are very common. SAP Commerce therefore includes a special mechanism resolving such dependencies. This mechanism assumes that all extensions which are not located within the <HYBRIS_BIN_DIR> /platform/ext directory have extension dependencies on the Platform extensions. Therefore, you do not have to specify <requires-extension> elements for the Platform extensions in your extensioninfo.xml file.
This mechanism is enabled or disabled using the autoload attribute in the localextensions.xml file. By default the autoload attribute is set to true, and the extension dependency resolving mechanism is enabled. This means you do not need to add the Platform extensions to your extensioninfo.xml file to specify dependencies. If you set this attribute explicitly to false, you have to add every needed extension in your localextensions.xml file. For details, refer to Installation Based on Specified Extensions.