Trying to deploy a managed package using ant migration tool getting the above message. Username and password+token from the scratch org are correct. I used the same credentials to test retrieving the dlrs package from scratch org A. I am trying to deploy it to scratch org B. Any ideas how to solve this issue or am I missing something. As I understand it, there is no need to retrieve any metadata from scratch Org A as a pre-requisite to deploy to scratch org B.

my build.xml

<project name="Sample usage of Salesforce Ant tasks" basedir="." xmlns:sf="antlib:com.salesforce">

    <property file="build.properties"/>
    <property environment="env"/>

        <import file="${basedir}/lib/ant-salesforce.xml"/>

    <condition property="sf.username" value=""> <not> <isset property="sf.username"/> </not> </condition>
    <condition property="sf.password" value=""> <not> <isset property="sf.password"/> </not> </condition>
    <condition property="sf.sessionId" value=""> <not> <isset property="sf.sessionId"/> </not> </condition>

    <taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce">
            <pathelement location="./lib/ant-salesforce.jar" />

    <target name="deploydlrs">
        <installPackage namespace="dlrs" version="2.5"
           username="${sf.username}" password="${sf.password}"/>

when I run ant deploydlrs, it correctly creates the following folder structure

enter image description here

but then I get this message

lib\ant-salesforce.xml:27: Invalid username, password, security token; or user locked out.

the salesforce.xml is copied from Andrew Fawcett. Username or password don't have characters that needs escaping.

  • Any reason you are not using the sfdx CLI package install command?
    – Phil W
    Apr 4, 2021 at 16:29
  • NB: the credentials will be specific to each org, including scratch orgs...
    – Phil W
    Apr 4, 2021 at 16:31
  • Good question, I am trying to automate the deployment process via ant. Yes I have two entries in my build.properties, sf.username for orgA and sf.username.orgB. this should be ok and it works when I retrieve
    – Mo Ali
    Apr 4, 2021 at 16:32
  • You can invoke sfdx commands from an ant script if you want to. Just use the standard CLI execution task.
    – Phil W
    Apr 4, 2021 at 16:36
  • I would recommend migrating away from the old Ant tasks Salesforce created. They are now replaced by sfdx, especially in the context of scratch orgs.
    – Phil W
    Apr 4, 2021 at 16:37

1 Answer 1


Don't use the Ant Migration Tool if you can help it. The sfdx-cli is much better, as you can simply script:

sfdx force:package:install -p [email protected] -u <desired-scratch-org-alias>

You simply need a sfdx-project.json file that includes the alias for it:

{ ...
  "packageAliases": {
    "[email protected]": "04t-package-id"

Also, having previously installed packages using Ant, this blog post includes a custom command, as installPackage isn't part of the core Ant package and takes more work to use. I used to use the deploy script, just specify the InstalledPackage metadata type with the relevant names:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">

This technically works, but is very annoying to maintain. The upside, however, is that you can simultaneously install many packages with a single package.xml file (I've installed about 10 packages at once this way).

  • just bear with me, you say stay away from ant migration tool, can the sfdx command be automated? if so how would I approach this
    – Mo Ali
    Apr 4, 2021 at 16:44
  • @MoAli Yes, you can use Windows Tasks or crontab, bash/sh/zsh/cmd/PowerShell/etc scripts, CI/CD (Jenkins, etc), and so on with sfdx cli. Also, it requires Node, but notably does not require Java in order to run, which makes it far more lightweight overall.
    – sfdcfox
    Apr 4, 2021 at 16:50
  • 1
    We have Ant scripting that invokes sfdx, and we also have yaml scripting that does the same. One of the benefits of both is OS portability.
    – Phil W
    Apr 4, 2021 at 18:16
  • 1
    @PhilW Good point. I'm mostly concerned about the Ant Migration Tool specifically. It's a relatively fickle piece of code that can be really obtuse to do pretty much anything.
    – sfdcfox
    Apr 4, 2021 at 20:11
  • 1
    @PhilW and sfdcfox well a good start for me, gulp tasks, came to the rescue. that is currently working although I am having other issues such as sfdx push standard objects but that is another question to ask at some point later.
    – Mo Ali
    Apr 5, 2021 at 15:36

You must log in to answer this question.

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