java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.maven.resolver.internal.ant.tasks.AbstractDistTask
org.apache.maven.resolver.internal.ant.tasks.Deploy
All Implemented Interfaces:
Cloneable

public class Deploy extends AbstractDistTask
Ant task to deploy artifacts to a remote Maven repository.

This task uploads artifacts, POM files, and optionally metadata such as licenses or dependencies to a remote repository using Maven Resolver. It mimics the behavior of mvn deploy but is integrated into Ant build scripts.

Usage Example:


 <repo:deploy>
   <repo:artifact file='build/libs/my-lib.jar'
             groupId='com.example'
             artifactId='my-lib'
             version='1.0.0'
             packaging='jar'/>
   <repo:repository id="snapshots" url='https://my.repo.com/snapshots'>
     <repo:authentication username='user' password='pass'/>
   </repo:repository>
 </repo:deploy>
 
* If you have used the pom task to register an existing POM, or you used the createPom task to generate and register a POM, you can instead do this:

 <repo:artifacts id='remoteArtifacts'>
       <repo:artifact refid='jar'/>
       <repo:artifact refid='sourceJar'/>
       <repo:artifact refid='javadocJar'/>
 </repo:artifacts>
 <repo:deploy artifactsref='remoteArtifacts'>
   <repo:remoteRepo id='localNexus', url='http://localhost:8081/repository/repo/'/>
 </repo:deploy>
 

Attributes:

  • failOnMissingPom — whether to fail if no POM information is provided (default: true)

Nested Elements:

  • <artifact> — specifies the artifact file and its coordinates to be deployed
  • <pom> — (optional) provides the POM file to upload, or one will be generated
  • <repository> — defines the target repository for deployment

Behavior:

  • If no POM is provided, a basic one will be generated using the artifact's metadata
  • Uploads artifacts using Maven's supported protocols (e.g., HTTP/S with authentication)
  • Supports deployment to both snapshot and release repositories

This task is typically used in CI/CD pipelines or custom release scripts that need to publish artifacts from Ant.

See Also:
  • Field Summary

    Fields inherited from class org.apache.tools.ant.Task

    target, taskName, taskType, wrapper

    Fields inherited from class org.apache.tools.ant.ProjectComponent

    description, location, project
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor for the Deploy task.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Allows ant to add a remote repository which artifacts will be deployed to.
    void
    addSnapshotRepo(RemoteRepository snapshotRepository)
    Adds a snapshot repository to which snapshot artifacts will be deployed.
    void
     
    void
    setRemoteRepoRef(org.apache.tools.ant.types.Reference ref)
    Sets a reference to a predefined <repository> element to be used as the deployment target.
    void
    setSnapshotRepoRef(org.apache.tools.ant.types.Reference ref)
    Sets a reference to a predefined <snapshotRepository> element.
    protected void
    Validates the configuration of the task before execution.

    Methods inherited from class org.apache.maven.resolver.internal.ant.tasks.AbstractDistTask

    addArtifact, addArtifacts, addPom, getArtifacts, getPom, setArtifactsRef, setPomRef

    Methods inherited from class org.apache.tools.ant.Task

    bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType

    Methods inherited from class org.apache.tools.ant.ProjectComponent

    clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Deploy

      public Deploy()
      Default constructor for the Deploy task.

      Initializes a new instance of the Deploy task.

  • Method Details

    • validate

      protected void validate()
      Description copied from class: AbstractDistTask
      Validates the configuration of the task before execution. Ensures there are no duplicate artifacts, that the POM is defined, and that each artifact's associated POM matches the main POM.
      Overrides:
      validate in class AbstractDistTask
    • addRemoteRepo

      public void addRemoteRepo(RemoteRepository repository)
      Allows ant to add a remote repository which artifacts will be deployed to.

      This method is invoked by Ant when a <repository> nested element is defined inside the <deploy> task. Each repository must specify a unique id and a deployment url, and may optionally include layout and authentication information.

      Multiple repositories can be specified, though typically only one is used for deployment.

      Example:
      
       <deploy>
         <artifact ... />
         <repository id="release"
                     url="https://repo.example.com/releases"
                     layout="default">
           <authentication username="user" password="pass"/>
         </repository>
       </deploy>
       
      Parameters:
      repository - the remote repository configuration to add
      See Also:
    • setRemoteRepoRef

      public void setRemoteRepoRef(org.apache.tools.ant.types.Reference ref)
      Sets a reference to a predefined <repository> element to be used as the deployment target.

      This allows the <deploy> task to reuse a RemoteRepository definition declared elsewhere in the build script using an id and refid.

      This is functionally equivalent to defining a <repository> nested element inline, but enables reuse across multiple deployment tasks.

      Example:
      
       <repository id="release.repo" url="https://repo.example.com/releases" layout="default">
         <authentication username="deploy" password="secret"/>
       </repository>
      
       <deploy>
         <artifact ... />
         <remoteRepo refid="release.repo"/>
       </deploy>
       
      Parameters:
      ref - the Ant reference to a <repository> definition
      See Also:
    • addSnapshotRepo

      public void addSnapshotRepo(RemoteRepository snapshotRepository)
      Adds a snapshot repository to which snapshot artifacts will be deployed.

      This method is invoked by Ant when a <snapshotRepository> nested element is defined within the <deploy> task. It provides a separate deployment target specifically for artifacts whose version ends with -SNAPSHOT.

      If no snapshot repository is provided, and a regular <repository> is defined, all artifacts (including snapshots) will be deployed to that single repository.

      Example:
      
       <deploy>
         <artifact ... />
      
         <repository id="release.repo" url="https://repo.example.com/releases"/>
      
         <snapshotRepository id="snapshot.repo" url="https://repo.example.com/snapshots">
           <authentication username="deploy" password="secret"/>
         </snapshotRepository>
       </deploy>
       
      Parameters:
      snapshotRepository - the snapshot repository configuration to use for -SNAPSHOT artifacts
      See Also:
    • setSnapshotRepoRef

      public void setSnapshotRepoRef(org.apache.tools.ant.types.Reference ref)
      Sets a reference to a predefined <snapshotRepository> element.

      This allows the <deploy> task to reuse an existing RemoteRepository configuration for deploying snapshot artifacts (i.e., versions ending in -SNAPSHOT).

      This is equivalent to defining a <snapshotRepository> nested element, but enables reuse across multiple tasks or modules by referencing a shared definition declared elsewhere in the build file.

      Example:
      
       <repository id="snap.repo" url="https://repo.example.com/snapshots" layout="default">
         <authentication username="deploy" password="secret"/>
       </repository>
      
       <deploy>
         <artifact ... />
         <snapshotRepository refid="snap.repo"/>
       </deploy>
       
      Parameters:
      ref - an Ant Reference to a snapshot repository definition
      See Also:
    • execute

      public void execute() throws org.apache.tools.ant.BuildException
      Overrides:
      execute in class org.apache.tools.ant.Task
      Throws:
      org.apache.tools.ant.BuildException