---
schema_version: "1"
id: 9bc7ef27611c71674c930d3be46e30f8ffea9474e017237ce157cc0894ddd131
title: Create Dependencies Between Second-Generation Managed Packages
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform-pkg-exchange/managed_packaging/guides/second-generation/sfdx-dev-dev2gp-create-dependencies.md
canonical_url: https://developer.salesforce.com/docs/platform/pkg2-dev/guide/sfdx-dev-dev2gp-create-dependencies.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 08d8c3c5215cbf8dce72f663f3ac31eb635b3adeefeb6981552cbadcb711a4f8
products:
  - Second-Generation Managed Packaging Developer Guide
  - merged-docs
---

# 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.

## How to Specify a Managed 2GP Package Dependency

**note:** To understand which combination of managed 2GP and managed 1GP package dependencies are supported, see [Which Package Types Can Your Package Depend On?](https://developer.salesforce.com/docs/atlas.en-us.pkg2_dev.meta/pkg2_dev/sfdx_dev_dev2gp_dependency_overview.htm).

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:

```javascript
"dependencies": [
   {
      "package": "MyPackageName@0.1.0.1"
   }
]
```

Example 2:

```javascript
"dependencies": [
   {
      "package": "MyPackageName",
      "versionNumber": "1.0.0.RELEASED"
   }
]
```

To specify a dependency on a managed package that isn’t associated with your Dev Hub:

```javascript
"dependencies": [
   {
      "package": "04txxx"
   }
]
```

**note:** You can use the RELEASED keyword for the version number to set the dependency.

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:

```javascript
"dependencies": [
   {
      "package" : "External Apex Library - 1.0.0.4"

    },
   {
      "package": "Expense Manager - Util",
      "versionNumber": "4.7.0.RELEASED"

   }
]
```

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:

```javascript
"dependencies": [
   {
      "package": "Expense Manager - Util",
      "versionNumber": "4.7.0.RELEASED"

   }
]
```

## 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.

![A diagram of a multilevel dependency where PkgC depends on PkgB, and PkgB depends on                         PkgA.](https://developer.salesforce.com/media/pkg2_dev/sfdx_packaging_multilevel_dependencies.png)

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.

```nolang
{
    "packageDirectories": [
        {
            "path": "pkgA-wsp",
            "default": true,
            "package": "pkgA",
            "versionName": "ver 1.3",
            "versionNumber": "1.3.0.NEXT",
            "ancestorVersion": "1.1.0.RELEASED"
        },
        {
            "path": "pkgB-wsp",
            "default": false,
            "package": "pkgB",
            "versionName": "ver 2.3",
            "versionNumber": "2.3.0.NEXT",
            "ancestorVersion": "2.0.0.RELEASED",
            "dependencies": [
                {
                   "package": "pkgA@1.1.0.RELEASED"
                }
             ]
        },
        {
            "path": "pkgC-wsp",
            "default": false,
            "package": "pkgC",
            "versionName": "ver 0.1",
            "versionNumber": "0.1.0.NEXT",
            "dependencies": [
                {
                   "package": "pkgA@1.1.0.RELEASED"
                },
                {
                    "package": "pkgB@2.0.0.RELEASED"
                }

             ]
        }
​
    ],

}
```

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.

```nolang
{
    "packageDirectories": [
        {
            "path": "pkgA-wsp",
            "default": true,
            "package": "pkgA",
            "versionName": "ver 1.3",
            "versionNumber": "1.3.0.NEXT",
            "ancestorVersion": "1.1.0.RELEASED"
        },
        {
            "path": "pkgB-wsp",
            "default": false,
            "package": "pkgB",
            "versionName": "ver 2.3",
            "versionNumber": "2.3.0.NEXT",
            "ancestorVersion": "2.0.0.RELEASED",
            "dependencies": [
                {
                   "package": "pkgA@1.1.0.RELEASED"
                }
             ]
        },
        {
            "path": "pkgC-wsp",
            "default": false,
            "package": "pkgC",
            "versionName": "ver 0.1",
            "versionNumber": "0.1.0.NEXT",
            "calculateTransitiveDependencies": true,
            "dependencies": [
                {
                    "package": "pkgB@2.0.0.RELEASED"
                }
             ]
        }
    ],
}
```

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.

**See Also**

- [Advanced Project Configuration Parameters for Second-Generation Managed Packages](https://developer.salesforce.com/docs/atlas.en-us.pkg2_dev.meta/pkg2_dev/sfdx_dev2gp_adv_config_file.htm)
- [Which Package Types Can Your Package Depend On?](https://developer.salesforce.com/docs/atlas.en-us.pkg2_dev.meta/pkg2_dev/sfdx_dev_dev2gp_dependency_overview.htm)
- [Considerations for Promoting Packages with Dependencies](https://developer.salesforce.com/docs/atlas.en-us.pkg2_dev.meta/pkg2_dev/dev2gp_considerations_pkg_dependency.htm)
