Class Deploy
- All Implemented Interfaces:
Cloneable
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, wrapperFields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRemoteRepo(RemoteRepository repository) Allows ant to add a remote repository which artifacts will be deployed to.voidaddSnapshotRepo(RemoteRepository snapshotRepository) Adds a snapshot repository to which snapshot artifacts will be deployed.voidexecute()voidsetRemoteRepoRef(org.apache.tools.ant.types.Reference ref) Sets a reference to a predefined<repository>element to be used as the deployment target.voidsetSnapshotRepoRef(org.apache.tools.ant.types.Reference ref) Sets a reference to a predefined<snapshotRepository>element.protected voidvalidate()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, setPomRefMethods 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, setTaskTypeMethods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
-
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:AbstractDistTaskValidates 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:
validatein classAbstractDistTask
-
addRemoteRepo
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 uniqueidand a deploymenturl, 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 aRemoteRepositorydefinition declared elsewhere in the build script using anidandrefid.This is functionally equivalent to defining a
Example:<repository>nested element inline, but enables reuse across multiple deployment tasks.<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
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
Example:<repository>is defined, all artifacts (including snapshots) will be deployed to that single repository.<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-SNAPSHOTartifacts- 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 existingRemoteRepositoryconfiguration for deploying snapshot artifacts (i.e., versions ending in-SNAPSHOT).This is equivalent to defining a
Example:<snapshotRepository>nested element, but enables reuse across multiple tasks or modules by referencing a shared definition declared elsewhere in the build file.<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 AntReferenceto a snapshot repository definition- See Also:
-
execute
public void execute() throws org.apache.tools.ant.BuildException- Overrides:
executein classorg.apache.tools.ant.Task- Throws:
org.apache.tools.ant.BuildException
-