Create Dependencies Between Second-Generation Managed Packages
To avoid monolithic package development practices, plan to develop smaller, modular packages that group similar functionality and components. You can then define the dependencies between these packages. A package dependency is when metadata contained in one package depends on metadata contained in another package. For example, defining dependencies allow you to extend the functionality of a base package with components and metadata located in a separate package.
To specify dependencies between managed packages associated with the same Dev Hub, use either the package version alias or a combination of the package name and the version number.
To specify a dependency on a managed package that isn’t associated with your Dev Hub:
1"dependencies": [2{3 "package": "04txxx"4}5]
You can use the RELEASED keyword for the version number to set the dependency.
Note
To denote dependencies with package IDs instead of package aliases, use:
The 0Ho ID if you specify the package ID along with the version number
The 04t ID if you specify only the package version ID
Specifying Multiple Package Dependencies
If your package has more than one dependency, provide a comma-separated list of packages in the order of installation.
For example, if your package depends on the package Expense Manager - Util, which in turn depends on the package External Apex Library, the package dependencies are:
If the package has multilevel dependencies, you can optionally set the calculateTransitiveDependencies parameter to true in the sfdx-project.json file. When calculateTransitiveDependencies is true, you can specify the package’s direct dependencies only, and the indirect (transitive) dependencies are calculated for you.
For example, if calculateTransitiveDependencies is enabled and the package depends on the package Expense Manager - Util, which in turn depends on the package External Apex Library, the package dependency is:
Circular Dependencies: Circular dependencies among packages aren’t supported. A circular dependency occurs when pkgC depends on pkgB, pkgB depends on pkgA, and pkgA depends on pkgC.
Multi-level Dependencies
Multi-level package dependencies are supported.
A multi-level dependency occurs when pkgC depends on pkgB, and pkgB depends on pkgA.
By default, you list all dependencies at all levels in the sfdx-project.json file. To specify only the package’s direct dependencies and have the indirect (transitive) dependencies calculated for you, you can optionally set calculateTransitiveDependencies to true in the sfdx-project.json file.
When calculateTransitiveDependencies is not enabled, list all dependencies in the sfdx-project.json file in the package installation order. In this example, pkgA must be installed first, followed by pkgB, and then pkgC. The dependencies specified for pkgC are both pkgA and pkgB.
When calculateTransitiveDependencies is set to true, specify each package’s direct dependencies only. In this example, pkgC depends on pkgB, pkgB depends on pkgA, and pkgC’s indirect dependency on pkgA is calculated for you.
The specified package version number also impacts the installation of package dependencies. Before pkgB can be installed, pkgA version 1.1 or higher must first be installed. If this condition isn’t met, the installation of pkgB fails.