2

Creating a second-generation Managed Package (2GP) that has a dependency on a released first-generation Managed Package (1GP).

This is what I want the version progression for the package Connector for Salesforce to be:

Version Name Version Number Notes
Aurora 2023 2.1.0.7 Last release of first-generation managed package
Aurora 2023.2 2.1.1.1 First release of second-generation managed package

Got the information about my 1GP (namespace = xyzzy) from its Packaging and Namespace Org with:

sfdx force:package1:version:list -u [email protected]
MetadataPackageVersionId MetadataPackageId Name Version ReleaseState BuildNumber
04t... 033.. Aurora 2023 2.1.0 Released 7

On my Dev Hub ([email protected]), I linked my namespace (with [email protected]) then created a 2GP like this:

sfdx force:package:create --name "Connector for Salesforce" --packagetype Managed --path force-app/
NAME VALUE
Package Id 0Ho...

Now for the sfdx-project.json...

{
  "namespace": "xyzzy",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "56.0",
  "packageDirectories": [
    {
      "default": true,
      "package": "Connector for Salesforce",
      "path": "force-app",
      "versionName": "Aurora 2023.2",
      "versionNumber": "2.1.1.NEXT",
      "definitionFile": "config/project-scratch-def.json",
      "dependencies": [
        {
          "package": "Connector for Salesforce (1GP)@2.1.0.7"
        }
      ]
    }
  ],
  "packageAliases": {
    "Connector for Salesforce": "0Ho...",
    "Connector for Salesforce (1GP)@2.1.0.7": "04t...",
    "Connector for Salesforce (1GP)": "033..."
  }
}

When I run

sfdx force:package:beta:version:create -p 0Ho... --installationkeybypass -b next

After recommendations from @Phil W below, the error is now...

ERROR running force:package:version:create: Can’t create patch version. Log a case in the Salesforce Partner Community and request that patch versioning be enabled in the org where you created the namespace for this package.

UPDATE: This error occurred because I was trying to make the first version of my second-generation managed package 2.1.0.NEXT instead of 1.0.0.NEXT. The reason I chose that version was to create continuity with my 1GP. Patch versioning was not needed. The error message from it was erroneous (and unhelpful).

7
  • I'm confused. Is Aurora the 1GP and you're trying to make it depend on the Connector 2GP? That seems to be what you've done in the sfdx-project.json comparing this with the detail you provided above that. If this is what you've done then you cannot; a 1GP cannot depend on a 2GP. If that's not what you've done I would say that you have the structure the wrong way round in the sfdx-project.json...
    – Phil W
    Jan 27 at 14:21
  • Cleaned up my question to make it clearer and implement some of your recommendations below. Jan 27 at 15:39
  • Do you really still have a question now you "cleaned up" the sfdx-project.json? What's still going wrong?
    – Phil W
    Jan 27 at 16:14
  • Ah, patch versioning. Have you had your package go through security review and pass? Only then can you have patching enabled...
    – Phil W
    Jan 27 at 16:14
  • The plan was to submit the 2GP package for the security review. We're in the process of becoming an ISV Partner and waiting on Salesforce legal's review. Wanted to get everything working using 2GP so the review is based on the latest/greatest. Jan 27 at 16:28

1 Answer 1

1

If "Aurora" is your 1GP and it is to be a dependency for your 2GP "Connector for Salesforce", your sfdx-project.json for your 2GP should be more like:

{
  "namespace": "xyzzy",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "56.0",
  "packageDirectories": [
    {
      "default": true,
      "package": "Connector for Salesforce",
      "path": "force-app",
      "versionName": "Connector for Salesforce 2.1.1",
      "versionNumber": "2.1.1.NEXT",
      "definitionFile": "config/project-scratch-def.json",
      "dependencies": [
        {
          "package": "[email protected]"
        }
      ]
    }
  ],
  "packageAliases": {
    "[email protected]": "04t..."
  }
}

You need to have the 2GP depend on the 1GP. I've used a package alias here to make that dependency more readable.

14
  • Thanks Phil. Aurora is the version name but your example is helpful. Let me give this a try. I will also update my question above and post results. Jan 27 at 15:16
  • Naming the 1GP and 2GP packages more-or-less the same is a bit strange.
    – Phil W
    Jan 27 at 16:13
  • Regarding the naming... no one has the 1GP (only installed once for testing on a Dev org). The only reason it was created in the first place was because Connected Apps have to be created in a 1GP otherwise, I would have started with 2GP and never had this dependency (frustrating). Jan 27 at 16:30
  • Do you really need a packaged Connected App? Is it a must that every install gets a different client ID/secret? Or could you use a shared Connected App created on your "Partner Business Org" (PBO; that's the CRM/production org for ISVs)? We took this latter approach. No need to package it, no need for 1GP.
    – Phil W
    Jan 27 at 16:35
  • Take a look at this and this for some more detail.
    – Phil W
    Jan 27 at 16:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .