Class Pom
- All Implemented Interfaces:
Cloneable
DataType.
This type allows an existing pom.xml file to be loaded into the Ant build environment.
The POM's metadata (such as groupId, artifactId, version, etc.) can be accessed directly or reused
in other Maven Resolver tasks like Deploy,
Install
Usage Example:
<pom file="target/generated-pom.xml" id="my.pom"/>
<echo message="Group ID is ${pom.groupId}"/>
<echo message="Version is ${pom.version}"/>
<deploy>
<pom refid="my.pom"/>
<repository id="release" url="https://repo.mycompany.com/releases"/>
</deploy>
Attributes:
- file — the path to the
pom.xmlfile to load
Exposed Ant Properties:
When a POM is loaded, the following properties become available for use in your build script:${pom.groupId}${pom.artifactId}${pom.version}${pom.packaging}${pom.name}${pom.description}(if present)
If you want a different property prefix, you can set it when you register the POM, e.g.:
<pom file="target/generated-pom.xml" id="my.pom" prefix="lib"/>
Typical Use Cases:
- Reusing existing Maven coordinates in Ant-based deployments
- Injecting POM metadata into artifact creation or reporting tasks
- Keeping build logic in sync with Maven configuration
- 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) Adds a single remote repository to this POM's list of repositories.voidaddRemoteRepos(RemoteRepositories repositories) Adds aRemoteRepositoriescontainer to this POM, which holds one or more remote repositories used to resolve dependencies and parent POMs when the POM is loaded from a file.voidexecute()Returns theartifactIdof the POM.Returns the raw Maven coordinates string that was set viasetCoords(String).getFile()Returns the file that was set viasetFile(File)to load the POM from.Returns thegroupIdof the POM.org.apache.maven.model.ModelgetModel(org.apache.tools.ant.Task task) Returns the parsed MavenModelassociated with this POM.Returns the packaging type of the POM, such asjar,pom, orwar.protected PomgetRef()Resolves this object if defined as a reference and verifies that it is aPominstance.Returns theversionof the Maven artifact defined by this POM.voidsetArtifactId(String artifactId) Sets theartifactIdfor the POM.voidSets the Maven coordinates for this POM using a compact string format.voidSets the file from which to load the POM.voidsetGroupId(String groupId) Sets thegroupIdfor the POM.voidSets the internal identifier for this POM.voidsetPackaging(String packaging) Sets the packaging type of the POM, such asjar,war,pom, etc.voidsetRefid(org.apache.tools.ant.types.Reference ref) Sets a reference to another task instance defined elsewhere in the build file.voidsetRemoteReposRef(org.apache.tools.ant.types.Reference ref) Adds a reference to aRemoteRepositoriesinstance to this POM's list of remote repositories.voidsetVersion(String version) Sets theversionof the POM.toString()voidvalidate()Validates that this POM definition is complete and usable.Methods inherited from class org.apache.maven.resolver.internal.ant.tasks.RefTask
checkAttributesAllowed, checkChildrenAllowed, getCheckedRef, getCheckedRef, getDataTypeName, isReference, noChildrenAllowed, tooManyAttributesMethods 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
-
Pom
public Pom()Creates an emptyPominstance.Attributes such as
groupId,artifactId, andversioncan be set individually, or the POM can be initialized from afileor via a reference (refid).Ant uses this constructor when instantiating the datatype from a build script.
- See Also:
-
-
Method Details
-
getRef
Resolves this object if defined as a reference and verifies that it is aPominstance.- Returns:
- the referenced
Pominstance - Throws:
org.apache.tools.ant.BuildException- if the reference is invalid- See Also:
-
validate
public void validate()Validates that this POM definition is complete and usable.If this object is a reference, validation is delegated to the referenced
Pom. Otherwise, the method checks that either aPOM fileis provided, or all of the required Maven coordinates —groupId,artifactId, andversion— are explicitly set.- Throws:
org.apache.tools.ant.BuildException- if required attributes are missing and no POM file is specified- See Also:
-
setRefid
public void setRefid(org.apache.tools.ant.types.Reference ref) Description copied from class:RefTaskSets a reference to another task instance defined elsewhere in the build file.Once set, no other attributes or nested elements should be specified on this task.
-
setId
Sets the internal identifier for this POM.This
idis not the same as Ant's built-inidattribute, but may be used internally by the task logic (e.g., for naming, logging, or referencing the POM).This method must not be used if this object is defined as a reference (
refid), or if attributes are otherwise disallowed in the current context.- Parameters:
id- the internal identifier to assign- Throws:
org.apache.tools.ant.BuildException- if attribute usage is disallowed- See Also:
-
getFile
Returns the file that was set viasetFile(File)to load the POM from.If a file was specified, it is used as the source for reading the POM’s metadata instead of defining coordinates manually. This is useful when you want to reference an existing
pom.xmlfile directly.If this
Pomis defined as a reference (refid), the file is retrieved from the referencedPominstance.- Returns:
- the POM file, or
nullif not set - See Also:
-
setFile
Sets the file from which to load the POM.This is an alternative to specifying Maven coordinates manually. When set, the POM's metadata is loaded directly from the given file.
This method must not be used in combination with:
setGroupId(String),setArtifactId(String),setVersion(String), orsetCoords(String)- or if this object is defined as a
refid
Doing so will raise a
BuildException.- Parameters:
file- the file containing the POM- Throws:
org.apache.tools.ant.BuildException- if attributes are in conflict or not allowed- See Also:
-
getGroupId
Returns thegroupIdof the POM.The group ID uniquely identifies the organization or project to which the artifact belongs, such as
org.apache.maven. This value is typically required when manually specifying Maven coordinates usingsetGroupId(String)orsetCoords(String).If this
Pomis defined as a reference (refid), the value is delegated to the referencedPominstance.- Returns:
- the group ID, or
nullif not set - See Also:
-
setGroupId
Sets thegroupIdfor the POM.The group ID typically represents the project's organization or domain, such as
org.apache.mavenorcom.example. This value is required when specifying coordinates manually.This method must not be called if:
groupIdhas already been set (directly or viasetCoords(String)),- or if a POM file has been specified via
setFile(java.io.File), - or if this object is defined via a
refid.
Violations will result in a
BuildException.- Parameters:
groupId- the Maven group ID- Throws:
org.apache.tools.ant.BuildException- if attributes are in conflict or not allowed- See Also:
-
getArtifactId
Returns theartifactIdof the POM.The artifact ID is the name that uniquely identifies the project within its group, such as
maven-resolver-ant-tasks.If this
Pomis defined as a reference (refid), the value is retrieved from the referenced instance.- Returns:
- the artifact ID, or
nullif not set - See Also:
-
setArtifactId
Sets theartifactIdfor the POM.The artifact ID identifies the project within its group, for example:
guice,junit, ormy-module. This value is required when manually specifying the Maven coordinates (groupId, artifactId, version).This method must not be called if:
artifactIdwas already set (directly or viasetCoords(String)),- or if a
filewas specified viasetFile(java.io.File), - or if this instance is a reference (
refid).
Violating these constraints will result in a
BuildException.- Parameters:
artifactId- the Maven artifact ID- Throws:
org.apache.tools.ant.BuildException- if attributes are in conflict or not allowed- See Also:
-
getVersion
Returns theversionof the Maven artifact defined by this POM.The version is one of the required coordinates for uniquely identifying a Maven artifact. If this object is defined as a reference (
refid), the version is retrieved from the referenced instance.If this POM is resolved from a file and uses a
dependencyManagementsection (e.g. via a BOM), the version may be inherited and not explicitly required here.- Returns:
- the version of the artifact, or
nullif not set and not resolved - See Also:
-
setVersion
Sets theversionof the POM.This value defines the version of the project artifact being referenced, such as
1.0.0or2.5-SNAPSHOT.This method must not be used if:
versionis already set (directly or viasetCoords(String)),- a POM file is specified via
setFile(java.io.File), - or this instance is defined as a
refid.
Violating these constraints will cause a
BuildException.- Parameters:
version- the Maven version- Throws:
org.apache.tools.ant.BuildException- if attributes are in conflict or not allowed- See Also:
-
getCoords
Returns the raw Maven coordinates string that was set viasetCoords(String).This string is typically in the format
groupId:artifactId:version, but may also include optional parts such as:extensionor:classifierdepending on the usage context.If this
Pomis defined as a reference (refid), the value is retrieved from the referenced instance.- Returns:
- the raw coordinate string, or
nullif not set - See Also:
-
setCoords
Sets the Maven coordinates for this POM using a compact string format.The expected format is
groupId:artifactId:version, where:groupIdis the group ID of the artifact, e.g.org.apache.mavenartifactIdis the artifact ID, e.g.maven-coreversionis the version, e.g.3.9.0
This method provides a concise alternative to setting each of
setGroupId(String),setArtifactId(String), andsetVersion(String)individually.Mutual exclusion: This method must not be used in combination with:
setGroupId(String),setArtifactId(String), orsetVersion(String)setFile(java.io.File)setRefid(org.apache.tools.ant.types.Reference)
BuildException.- Parameters:
coords- the Maven coordinates in the formatgroupId:artifactId:version- Throws:
org.apache.tools.ant.BuildException- if the format is invalid or attributes conflict- See Also:
-
getPackaging
Returns the packaging type of the POM, such asjar,pom, orwar.This value is typically set via
setPackaging(String)or resolved from a parsed POM file. If not explicitly set, the default packaging is usuallyjar.If this
Pomis defined as a reference (refid), the packaging is retrieved from the referencedPominstance.- Returns:
- the packaging type, or
nullif not set - See Also:
-
setPackaging
Sets the packaging type of the POM, such asjar,war,pom, etc.This value determines how the artifact is packaged and what build lifecycle it uses. If not specified, Maven assumes a default of
jar.This method must not be used if a POM file has been specified via
setFile(java.io.File), or if this object is defined as a reference (refid). Violating these constraints will result in aBuildException.- Parameters:
packaging- the packaging type to assign to the POM- Throws:
org.apache.tools.ant.BuildException- if attributes are in conflict or not allowed- See Also:
-
addRemoteRepo
Adds a single remote repository to this POM's list of repositories.These repositories are used when resolving artifacts related to this POM, such as parent POMs or dependencies, especially when the POM is loaded from a file.
This method delegates to
getRemoteRepos()and appends the givenRemoteRepositoryto the internalRemoteRepositoriescontainer.- Parameters:
repository- the remote repository to add- See Also:
-
addRemoteRepos
Adds aRemoteRepositoriescontainer to this POM, which holds one or more remote repositories used to resolve dependencies and parent POMs when the POM is loaded from a file.This method delegates to
getRemoteRepos()and appends the given repository container to the list of remote repositories associated with this POM.- Parameters:
repositories- a container of remote repositories to add- See Also:
-
setRemoteReposRef
public void setRemoteReposRef(org.apache.tools.ant.types.Reference ref) Adds a reference to aRemoteRepositoriesinstance to this POM's list of remote repositories.This allows remote repositories to be defined elsewhere in the build script and referenced by ID, promoting reuse and separation of concerns.
Internally, this method creates a new
RemoteRepositoriesobject, sets the reference ID, and delegates togetRemoteRepos()to append it to the list.- Parameters:
ref- the AntReferenceto aRemoteRepositoriesdefinition- See Also:
-
getModel
public org.apache.maven.model.Model getModel(org.apache.tools.ant.Task task) Returns the parsed MavenModelassociated with this POM.If a
filehas been specified viasetFile(java.io.File), the model is lazily loaded and cached using theAntRepoSysinstance for the current AntProject. If no file is set, this method returnsnull.If this
Pomis defined as a reference (refid), the model is retrieved from the referencedPominstance.This method is thread-safe and performs lazy loading: the model is loaded only once and reused on subsequent calls.
- Parameters:
task- the Ant task context used for logging and error reporting during model loading- Returns:
- the Maven
Modelparsed from the specified POM file, ornullif no file was set - See Also:
-
execute
public void execute()- Overrides:
executein classorg.apache.tools.ant.Task
-
toString
-