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.Artifact
All Implemented Interfaces:
Cloneable, ArtifactContainer

public class Artifact extends RefTask implements ArtifactContainer
Represents a Maven artifact in an Ant build script.

This type encapsulates the essential coordinates of a Maven artifact — such as groupId, artifactId, version, packaging, and optional classifier — along with the actual artifact file to be installed or deployed.

<artifact> elements are typically used as nested elements inside Install or Deploy tasks.

Usage Example:


 <repo:install>
   <repo:artifact
     file="build/libs/my-lib-1.0.0.jar"
     groupId="com.example"
     artifactId="my-lib"
     version="1.0.0"
     packaging="jar"/>
 </repo:install>
 
Alternatively, you can register the artifact after it is created by the jar task and then just refer to it, e.g.:

 <target name='jar' depends='compile'>
     <property name='jarFile' value='${targetDir}/${artifactId}-${version}.jar'/>
     <jar destfile='${jarFile}'>
         <fileset dir='${mainBuildDir}'/>
     </jar>
     <repo:artifact file='${jarFile}' type='jar' id='mainJar'/>
 </target>

 <target name='install' depends='jar'>
     <repo:artifacts id='localArtifacts'>
         <repo:artifact refid='mainJar'/>
     </repo:artifacts>
     <repo:install artifactsref='localArtifacts'/>
 </target>
 

Attributes:

  • id — the refId to use when referring to it, e.g., when combining several artifact with the artifacts tag
  • file — the actual artifact file to install or deploy (required)
  • groupId — the Maven groupId of the artifact
  • artifactId — the Maven artifactId
  • version — the artifact version
  • packaging — the type/extension of the artifact (e.g., jar, pom) (required)
  • classifier — optional classifier (e.g., sources, javadoc)

Typical Use Cases:

  • Publishing pre-built artifacts from Ant to a Maven repository
  • Installing locally built binaries into the local Maven repository
  • Providing coordinates for deployment without a POM
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 Artifact data type.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addPom(Pom pom)
    Adds a nested Pom element to associate with this artifact.
    void
    Registers this artifact in the ProjectWorkspaceReader for internal resolution.
    Returns a list containing this single artifact.
    Returns the optional classifier of the artifact (e.g., sources, javadoc).
    Returns the artifact file.
    Returns the associated POM for this artifact, if any.
    protected Artifact
    Resolves this object if defined as a reference and verifies that it is a Artifact instance.
    Returns the type/packaging of the artifact (e.g., jar, pom).
    void
    setClassifier(String classifier)
    Sets the optional classifier for the artifact.
    void
    setFile(File file)
    Sets the artifact file to be deployed or installed.
    void
    setPomRef(org.apache.tools.ant.types.Reference ref)
    Sets a reference to a Pom element to associate with this artifact.
    void
    setRefid(org.apache.tools.ant.types.Reference ref)
    Sets a reference to another Artifact instance.
    void
    Sets the artifact's packaging or type (e.g., jar, pom).
    Returns a string representation of the artifact, showing its type and classifier.
    void
    validate(org.apache.tools.ant.Task task)
    Validates that all required attributes are present and that the file exists.

    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

    • Artifact

      public Artifact()
      Default constructor for the Artifact data type.
  • Method Details

    • getRef

      protected Artifact getRef()
      Resolves this object if defined as a reference and verifies that it is a Artifact instance.
      Returns:
      the referenced Artifact instance
      Throws:
      org.apache.tools.ant.BuildException - if the reference is invalid
    • validate

      public void validate(org.apache.tools.ant.Task task)
      Validates that all required attributes are present and that the file exists.
      Specified by:
      validate in interface ArtifactContainer
      Parameters:
      task - the Ant task that owns this data type (used for context in error messages)
      Throws:
      org.apache.tools.ant.BuildException - if required attributes are missing or invalid
    • setRefid

      public void setRefid(org.apache.tools.ant.types.Reference ref)
      Sets a reference to another Artifact instance.
      Overrides:
      setRefid in class RefTask
      Parameters:
      ref - the reference ID
      Throws:
      org.apache.tools.ant.BuildException - if conflicting attributes are already set
    • getFile

      public File getFile()
      Returns the artifact file.
      Returns:
      the artifact file
    • setFile

      public void setFile(File file)
      Sets the artifact file to be deployed or installed.
      Parameters:
      file - the artifact file
    • getType

      public String getType()
      Returns the type/packaging of the artifact (e.g., jar, pom).
      Returns:
      the artifact type
    • setType

      public void setType(String type)
      Sets the artifact's packaging or type (e.g., jar, pom).
      Parameters:
      type - the artifact type
    • getClassifier

      public String getClassifier()
      Returns the optional classifier of the artifact (e.g., sources, javadoc).
      Returns:
      the classifier or an empty string if not set
    • setClassifier

      public void setClassifier(String classifier)
      Sets the optional classifier for the artifact.
      Parameters:
      classifier - the classifier
    • setPomRef

      public void setPomRef(org.apache.tools.ant.types.Reference ref)
      Sets a reference to a Pom element to associate with this artifact.
      Parameters:
      ref - the reference to the POM
    • addPom

      public void addPom(Pom pom)
      Adds a nested Pom element to associate with this artifact.
      Parameters:
      pom - the POM object
    • getPom

      public Pom getPom()
      Returns the associated POM for this artifact, if any.
      Returns:
      the POM object, or null if none is set
    • getArtifacts

      public List<Artifact> getArtifacts()
      Returns a list containing this single artifact.
      Specified by:
      getArtifacts in interface ArtifactContainer
      Returns:
      a singleton list with this artifact
    • execute

      public void execute() throws org.apache.tools.ant.BuildException
      Registers this artifact in the ProjectWorkspaceReader for internal resolution.
      Overrides:
      execute in class org.apache.tools.ant.Task
      Throws:
      org.apache.tools.ant.BuildException
    • toString

      public String toString()
      Returns a string representation of the artifact, showing its type and classifier.
      Overrides:
      toString in class Object
      Returns:
      a human-readable string describing the artifact