[SalesForce] How to create unlocked package version with dependency to managed package

I'm trying to create a package version to an unlocked package I've created and keep getting error messages.

The first problem I've encountered was a long error message about invalid type and variables that does not exists:

ERROR running force:package:version:create:  

User_TriggerHandler: Invalid type: Schema.Menora_Metadata_Setting__mdt,
User_TriggerHandler: Variable does not exist: openIncidentsByStaffId,
User_TriggerHandler: Variable does not exist: openIncidentsByStaffId,
User_TriggerHandler: Invalid type: BMCServiceDesk__Incident__c,
User_TriggerHandler: Variable does not exist: openIncidentsByStaffId,
User_TriggerHandler: Invalid type: BMCServiceDesk__Incident__c,
TRG_User_AfterUpdate: Variable does not exist: MNR_Action_AccountLink__c,
User_Tests: Field does not exist: BMCServiceDesk__IsStaffUser__c on User,
User_Tests: Field does not exist: MNR_OrgUnitName__c on User,
User_Tests: Variable does not exist: incidents,
User_Tests: DML requires SObject or SObject list type: List<BMCServiceDesk__Incident__c>,
User_Tests: Invalid type: BMCServiceDesk__Incident__c,
User_Tests: Invalid type: BMCServiceDesk__Incident__c,
User_Tests: Invalid type: BMCServiceDesk__Incident__c,
User_Tests: Invalid type: BMCServiceDesk__Category__c,
User_Tests: Invalid type: BMCServiceDesk__BMC_BaseElement__c,
User_Tests: Invalid type: BMCServiceDesk__BMC_BaseElement__c,
User_Tests: Invalid type: BMCServiceDesk__Incident__c,
User_Tests: Variable does not exist: incident,
User_Tests: Variable does not exist: incident,
User_Tests: Invalid type: BMCServiceDesk__Incident__c,
User_Tests: Invalid type: BMCServiceDesk__Incident__c,
User_Tests: Variable does not exist: incident,
User_Tests: Variable does not exist: incident,
User_Tests: Invalid type: Schema.Menora_Metadata_Setting__mdt,
User_TriggerHandler: Invalid type: BMCServiceDesk__Incident__c,
User_TriggerHandler: Invalid type: BMCServiceDesk__Incident__c,
User_Tests: Field does not exist: MNR_CustomerCode__c on User,
User_TriggerHandler: Invalid type: Schema.Menora_Metadata_Setting__mdt,
User_TriggerHandler: Invalid type: Schema.Menora_Metadata_Setting__mdt,
User_TriggerHandler: Invalid type: Schema.Menora_Metadata_Setting__mdt,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: Profiles_on_Custom_Hierarchy_Settings__c,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: Incident_Custom_Settings__c,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: BI_Custom_Settings__c,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: QC_Custom_Settings__c,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: Electra_Interface_Settings__c,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: MNR_EnvironmentStaticSettings__c,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: User_Custom_Settings__c,
User_TriggerHandler: Variable does not exist: openIncidentsByStaffId,
User_TriggerHandler: Invalid type: BMCServiceDesk__Incident__c,
User_TriggerHandler: Variable does not exist: incident,User_TriggerHandler: Invalid type: Schema.BMCServiceDesk__Incident__c,
User_Tests: Invalid type: BMCServiceDesk__Category__c,
User_Tests: Invalid type: BMCServiceDesk__BMC_BaseElement__c,
User_Tests: Invalid type: BMCServiceDesk__BMC_BaseElement__c,
RemoveInactiveUsersFromIncidentsStaff: Class RemoveInactiveUsersFromIncidentsStaff must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext, List<SObject>),
User_Tests: Invalid type: BMCServiceDesk__Category__c,
User_Tests: Invalid type: BMCServiceDesk__BMC_BaseElement__c,
User_Tests: Invalid type: BMCServiceDesk__BMC_BaseElement__c,
User_Tests: Invalid type: Incident_Custom_Settings__c,
User_Tests: Invalid type: BI_Custom_Settings__c,
User_Tests: Invalid type: QC_Custom_Settings__c,
User_Tests: Invalid type: Electra_Interface_Settings__c,
User_Tests: Invalid type: Profiles_on_Custom_Hierarchy_Settings__c,
User_Tests: Invalid type: Role_to_Profile_Mapping__c,
User_Tests: Invalid type: User_Custom_Settings__c,
User_Tests: Invalid type: MNR_EnvironmentStaticSettings__c,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: Role_to_Profile_Mapping__c

I tried to solve this by adding the managed package dependency to the sfdc-project.json file like this:

{
    "packageDirectories": [
        {
            "path": "force-app",
            "default": true,
            "package": "User",
            "versionName": "Version 1.0",
            "versionNumber": "1.0.0.NEXT",
            "dependencies":[
                {
                    //This didn't work
                    "package": "04t***QAE"

                    //This also didn't work
                    "subscriberPackageVersionId": "04t***QAE"
                }
            ]
        }
    ],
    "namespace": "",
    "sfdcLoginUrl": "https://login.salesforce.com",
    "sourceApiVersion": "47.0",
    "packageAliases": {
        "User": "0Ho***SA0"
    }
}

The problem at this point is that while I don't get the Invalid Type error anymore, the creation of the version is now stuck in the Verifying Dependencies status, no matter how much time I give it:

Request in progress. Sleeping 30 seconds. Will wait a total of 300 more seconds before timing out. Current Status='Initializing'
Request in progress. Sleeping 30 seconds. Will wait a total of 270 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 240 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 210 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 180 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 150 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 120 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 90 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 60 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 30 more seconds before timing out. Current Status='Verifying dependencies'
Package version creation request status is 'Verifying dependencies'. Run "sfdx force:package:version:create:report -i 08c5J0000008ORCQA2" to query for status.

Running the report command provides the following details:

=== Package Version Create Request
NAME                           VALUE
─────────────────────────────  ──────────────────────
ID                             08c***QA2
Status                         Verifying dependencies
Package Id                     0Ho***SA0
Package Version Id
Subscriber Package Version Id
Tag
Branch
Created Date                   2020-01-22 16:46
Installation URL

I've read this answer and this but applying the suggestions given there didn't help. I'm at lost.

Update
After setting the –wait flag to 60 minutes I got the following results:

..
...
Request in progress. Sleeping 30 seconds. Will wait a total of 1500 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 1470 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 1440 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 1410 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 1380 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 1350 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 1320 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 1290 more seconds before timing out. Current Status='Verifying metadata'
ERROR running force:package:version:create:  
RemoveInactiveUsersFromIncidentsStaff: Class RemoveInactiveUsersFromIncidentsStaff must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext,List<SObject>),
User_Tests: Invalid type: BMCServiceDesk__Category__c,
User_Tests: Invalid type: BMCServiceDesk__Category__c,
User_Tests: Invalid type: BMCServiceDesk__BMC_BaseElement__c,
User_Tests: Invalid type: BMCServiceDesk__BMC_BaseElement__c,
User_Tests: Invalid type: BMCServiceDesk__BMC_BaseElement__c,
User_Tests: Invalid type: BMCServiceDesk__BMC_BaseElement__c,
User_Tests: Invalid type: Incident_Custom_Settings__c,
User_Tests: Invalid type: BI_Custom_Settings__c,
User_Tests: Invalid type: QC_Custom_Settings__c,
User_Tests: Invalid type: Electra_Interface_Settings__c,
User_Tests: Invalid type: Profiles_on_Custom_Hierarchy_Settings__c,
User_Tests: Invalid type: Role_to_Profile_Mapping__c,
User_Tests: Invalid type: User_Custom_Settings__c,
User_Tests: Invalid type: MNR_EnvironmentStaticSettings__c,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: Role_to_Profile_Mapping__c,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: Profiles_on_Custom_Hierarchy_Settings__c,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: Incident_Custom_Settings__c,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: BI_Custom_Settings__c,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: QC_Custom_Settings__c,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: Electra_Interface_Settings__c,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: MNR_EnvironmentStaticSettings__c,
User_Tests: Initial expression is of incorrect type, expected: SObject but was: User_Custom_Settings__c,
User_Tests: Field does not exist: MNR_CustomerCode__c on User,
User_Tests: Field does not exist: MNR_OrgUnitName__c on User,
User_Tests: Invalid type: BMCServiceDesk__Incident__c,
User_Tests: Invalid type: BMCServiceDesk__Category__c,
User_Tests: Invalid type: BMCServiceDesk__BMC_BaseElement__c,
User_Tests: Invalid type: BMCServiceDesk__BMC_BaseElement__c,
User_Tests: Invalid type: BMCServiceDesk__Incident__c,User_Tests: Variable does not exist: incidents,
User_Tests: DML requires SObject or SObject list type: List<BMCServiceDesk__Incident__c>,
User_Tests: Invalid type: BMCServiceDesk__Incident__c,
User_Tests: Invalid type: BMCServiceDesk__Incident__c,
User_Tests: Variable does not exist: incident,
User_Tests: Variable does not exist: incident,
User_Tests: Invalid type: BMCServiceDesk__Incident__c,
User_Tests: Invalid type: BMCServiceDesk__Incident__c,
User_Tests: Variable does not exist: incident,
User_Tests: Variable does not exist: incident,
User_Tests: Invalid type: Schema.Menora_Metadata_Setting__mdt,
User_TriggerHandler: Invalid type: BMCServiceDesk__Incident__c,
User_TriggerHandler: Invalid type: BMCServiceDesk__Incident__c,
User_TriggerHandler: Invalid type: Schema.Menora_Metadata_Setting__mdt,
User_TriggerHandler: Invalid type: Schema.Menora_Metadata_Setting__mdt,
User_TriggerHandler: Invalid type: Schema.Menora_Metadata_Setting__mdt,
User_TriggerHandler: Invalid type: Schema.Menora_Metadata_Setting__mdt,
User_TriggerHandler: Variable does not exist: openIncidentsByStaffId,
User_TriggerHandler: Variable does not exist: openIncidentsByStaffId,
User_TriggerHandler: Invalid type: BMCServiceDesk__Incident__c,
User_TriggerHandler: Variable does not exist: openIncidentsByStaffId,
User_TriggerHandler: Invalid type: BMCServiceDesk__Incident__c,
User_TriggerHandler: Invalid type: Schema.BMCServiceDesk__Incident__c,
User_TriggerHandler: Invalid type: BMCServiceDesk__Incident__c,
User_TriggerHandler: Variable does not exist: openIncidentsByStaffId,
User_TriggerHandler: Variable does not exist: incident,
TRG_User_AfterUpdate: Variable does not exist: MNR_Action_AccountLink__c

So now the status is Verifying Metadata, but the version creation is still failing.

Thank you all in advance,
Lior.

Best Answer

In the following document youll find some common scenarios which might help - https://sfdc-db-gmail.github.io/unlocked-packages/faq-unlocked-pkgs.html#specify-pkg-dep

When declaring dependencies you should match between your package aliases.

"dependencies": [
                {
                    "package": "yourManagedPackageAlias"
                },
               ... ],
    ... ],
"packageAliases": {
        "yourManagedPackageAlias":  "04tXX...",
Related Topic