Newer Version Available

This content describes an older version of this product. View Latest

Create Dependencies Between Second-Generation Managed Packages

To avoid monolithic package development practices, you 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.

How to Specify a Managed 2GP Package Dependency

To understand which combination of managed 2GP and managed 1GP package dependencies are supported, see Which Package Dependencies Work with Second-Generation Managed Packages?.

Note

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.

Example 1:
1"dependencies": [ 
2   {
3      "package": "MyPackageName@0.1.0.1"
4   }
5]
Example 2:
1"dependencies": [ 
2   {
3      "package": "MyPackageName",
4      "versionNumber": "0.1.0.LATEST"
5   }
6]
To specify a dependency on a managed package that isn’t associated with your Dev Hub:
1"dependencies": [ 
2   {
3      "package": "OtherOrgPackage@1.2.0"
4   }
5]

You can use the LATEST 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:
1"dependencies": [
2   {
3      "package" : "External Apex Library - 1.0.0.4"
4
5    },
6   {
7      "package": "Expense Manager - Util",
8      "versionNumber": "4.7.0.LATEST"
9
10   }
11]

Which Types of Dependencies Are Supported?

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.
List multi-level dependencies in the sfdx-project.json file in package installation order. In this example, pkgA must be installed first, followed by pkgB, and then pkgC.
1{
2    "packageDirectories": [
3        {
4            "path": "pkgA-wsp",
5            "default": true,
6            "package": "pkgA",
7            "versionName": "ver 0.9",
8            "versionNumber": "0.9.0.NEXT",
9            "ancestorVersion": "0.7.0.1"
10        },
11        {
12            "path": "pkgB-wsp",
13            "default": false,
14            "package": "pkgB",
15            "versionName": "ver 0.3",
16            "versionNumber": "0.3.0.NEXT",
17            "dependencies": [ 
18                {
19                   "package": "pkgA@0.9.0.LATEST"
20                }
21             ]
22        },
23        {
24            "path": "pkgC-wsp",
25            "default": false,
26            "package": "pkgC",
27            "versionName": "ver 0.1",
28            "versionNumber": "0.1.0.NEXT",
29            "dependencies": [ 
30                {
31                   "package": "pkgA@0.9.0.LATEST"
32                },
33                {
34                    "package": "pkgB@0.3.0.LATEST"
35                }
36               
37             ]
38        }
39
40    ],
41    
42}
The specified package version number also impacts the installation of package dependencies. Before pkgB can be installed, pkgA version 0.9 or higher must first be installed. If this condition isn’t met, the installation of pkgB fails.