java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.maven.resolver.internal.ant.tasks.RefTask
org.apache.maven.resolver.internal.ant.types.Pom
All Implemented Interfaces:
Cloneable

public class Pom extends RefTask
Represents a Maven POM file as an Ant 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.xml file 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)
These properties enable consistent reuse of project metadata across Ant targets and tasks.

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, wrapper

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

    description, location, project
  • Constructor Summary

    Constructors
    Constructor
    Description
    Pom()
    Creates an empty Pom instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a single remote repository to this POM's list of repositories.
    void
    Adds a RemoteRepositories container 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.
    void
     
    Returns the artifactId of the POM.
    Returns the raw Maven coordinates string that was set via setCoords(String).
    Returns the file that was set via setFile(File) to load the POM from.
    Returns the groupId of the POM.
    org.apache.maven.model.Model
    getModel(org.apache.tools.ant.Task task)
    Returns the parsed Maven Model associated with this POM.
    Returns the packaging type of the POM, such as jar, pom, or war.
    protected Pom
    Resolves this object if defined as a reference and verifies that it is a Pom instance.
    Returns the version of the Maven artifact defined by this POM.
    void
    setArtifactId(String artifactId)
    Sets the artifactId for the POM.
    void
    setCoords(String coords)
    Sets the Maven coordinates for this POM using a compact string format.
    void
    setFile(File file)
    Sets the file from which to load the POM.
    void
    setGroupId(String groupId)
    Sets the groupId for the POM.
    void
    Sets the internal identifier for this POM.
    void
    setPackaging(String packaging)
    Sets the packaging type of the POM, such as jar, war, pom, etc.
    void
    setRefid(org.apache.tools.ant.types.Reference ref)
    Sets a reference to another task instance defined elsewhere in the build file.
    void
    setRemoteReposRef(org.apache.tools.ant.types.Reference ref)
    Adds a reference to a RemoteRepositories instance to this POM's list of remote repositories.
    void
    setVersion(String version)
    Sets the version of the POM.
     
    void
    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, tooManyAttributes

    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, wait, wait, wait
  • Constructor Details

  • Method Details

    • getRef

      protected Pom getRef()
      Resolves this object if defined as a reference and verifies that it is a Pom instance.
      Returns:
      the referenced Pom instance
      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 a POM file is provided, or all of the required Maven coordinates — groupId, artifactId, and version — 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: RefTask
      Sets 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.

      Overrides:
      setRefid in class RefTask
      Parameters:
      ref - the reference to another task
    • setId

      public void setId(String id)
      Sets the internal identifier for this POM.

      This id is not the same as Ant's built-in id attribute, 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

      public File getFile()
      Returns the file that was set via setFile(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.xml file directly.

      If this Pom is defined as a reference (refid), the file is retrieved from the referenced Pom instance.

      Returns:
      the POM file, or null if not set
      See Also:
    • setFile

      public void setFile(File file)
      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:

      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

      public String getGroupId()
      Returns the groupId of 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 using setGroupId(String) or setCoords(String).

      If this Pom is defined as a reference (refid), the value is delegated to the referenced Pom instance.

      Returns:
      the group ID, or null if not set
      See Also:
    • setGroupId

      public void setGroupId(String groupId)
      Sets the groupId for the POM.

      The group ID typically represents the project's organization or domain, such as org.apache.maven or com.example. This value is required when specifying coordinates manually.

      This method must not be called if:

      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

      public String getArtifactId()
      Returns the artifactId of the POM.

      The artifact ID is the name that uniquely identifies the project within its group, such as maven-resolver-ant-tasks.

      If this Pom is defined as a reference (refid), the value is retrieved from the referenced instance.

      Returns:
      the artifact ID, or null if not set
      See Also:
    • setArtifactId

      public void setArtifactId(String artifactId)
      Sets the artifactId for the POM.

      The artifact ID identifies the project within its group, for example: guice, junit, or my-module. This value is required when manually specifying the Maven coordinates (groupId, artifactId, version).

      This method must not be called if:

      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

      public String getVersion()
      Returns the version of 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 dependencyManagement section (e.g. via a BOM), the version may be inherited and not explicitly required here.

      Returns:
      the version of the artifact, or null if not set and not resolved
      See Also:
    • setVersion

      public void setVersion(String version)
      Sets the version of the POM.

      This value defines the version of the project artifact being referenced, such as 1.0.0 or 2.5-SNAPSHOT.

      This method must not be used if:

      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

      public String getCoords()
      Returns the raw Maven coordinates string that was set via setCoords(String).

      This string is typically in the format groupId:artifactId:version, but may also include optional parts such as :extension or :classifier depending on the usage context.

      If this Pom is defined as a reference (refid), the value is retrieved from the referenced instance.

      Returns:
      the raw coordinate string, or null if not set
      See Also:
    • setCoords

      public void setCoords(String coords)
      Sets the Maven coordinates for this POM using a compact string format.

      The expected format is groupId:artifactId:version, where:

      • groupId is the group ID of the artifact, e.g. org.apache.maven
      • artifactId is the artifact ID, e.g. maven-core
      • version is the version, e.g. 3.9.0

      This method provides a concise alternative to setting each of setGroupId(String), setArtifactId(String), and setVersion(String) individually.

      Mutual exclusion: This method must not be used in combination with:

      Violating this constraint will result in a BuildException.
      Parameters:
      coords - the Maven coordinates in the format groupId:artifactId:version
      Throws:
      org.apache.tools.ant.BuildException - if the format is invalid or attributes conflict
      See Also:
    • getPackaging

      public String getPackaging()
      Returns the packaging type of the POM, such as jar, pom, or war.

      This value is typically set via setPackaging(String) or resolved from a parsed POM file. If not explicitly set, the default packaging is usually jar.

      If this Pom is defined as a reference (refid), the packaging is retrieved from the referenced Pom instance.

      Returns:
      the packaging type, or null if not set
      See Also:
    • setPackaging

      public void setPackaging(String packaging)
      Sets the packaging type of the POM, such as jar, 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 a BuildException.

      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

      public void addRemoteRepo(RemoteRepository repository)
      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 given RemoteRepository to the internal RemoteRepositories container.

      Parameters:
      repository - the remote repository to add
      See Also:
    • addRemoteRepos

      public void addRemoteRepos(RemoteRepositories repositories)
      Adds a RemoteRepositories container 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 a RemoteRepositories instance 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 RemoteRepositories object, sets the reference ID, and delegates to getRemoteRepos() to append it to the list.

      Parameters:
      ref - the Ant Reference to a RemoteRepositories definition
      See Also:
    • getModel

      public org.apache.maven.model.Model getModel(org.apache.tools.ant.Task task)
      Returns the parsed Maven Model associated with this POM.

      If a file has been specified via setFile(java.io.File), the model is lazily loaded and cached using the AntRepoSys instance for the current Ant Project. If no file is set, this method returns null.

      If this Pom is defined as a reference (refid), the model is retrieved from the referenced Pom instance.

      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 Model parsed from the specified POM file, or null if no file was set
      See Also:
    • execute

      public void execute()
      Overrides:
      execute in class org.apache.tools.ant.Task
    • toString

      public String toString()
      Overrides:
      toString in class Object