Class Artifact
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
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 theartifacts
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 -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a nestedPom
element to associate with this artifact.void
execute()
Registers this artifact in theProjectWorkspaceReader
for internal resolution.Returns a list containing this single artifact.Returns the optional classifier of the artifact (e.g.,sources
,javadoc
).getFile()
Returns the artifact file.getPom()
Returns the associated POM for this artifact, if any.protected Artifact
getRef()
Resolves this object if defined as a reference and verifies that it is aArtifact
instance.getType()
Returns the type/packaging of the artifact (e.g.,jar
,pom
).void
setClassifier
(String classifier) Sets the optional classifier for the artifact.void
Sets the artifact file to be deployed or installed.void
setPomRef
(org.apache.tools.ant.types.Reference ref) Sets a reference to aPom
element to associate with this artifact.void
setRefid
(org.apache.tools.ant.types.Reference ref) Sets a reference to anotherArtifact
instance.void
Sets the artifact's packaging or type (e.g.,jar
,pom
).toString()
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
-
Constructor Details
-
Artifact
public Artifact()Default constructor for theArtifact
data type.
-
-
Method Details
-
getRef
Resolves this object if defined as a reference and verifies that it is aArtifact
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 interfaceArtifactContainer
- 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 anotherArtifact
instance. -
getFile
Returns the artifact file.- Returns:
- the artifact file
-
setFile
Sets the artifact file to be deployed or installed.- Parameters:
file
- the artifact file
-
getType
Returns the type/packaging of the artifact (e.g.,jar
,pom
).- Returns:
- the artifact type
-
setType
Sets the artifact's packaging or type (e.g.,jar
,pom
).- Parameters:
type
- the artifact type
-
getClassifier
Returns the optional classifier of the artifact (e.g.,sources
,javadoc
).- Returns:
- the classifier or an empty string if not set
-
setClassifier
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 aPom
element to associate with this artifact.- Parameters:
ref
- the reference to the POM
-
addPom
Adds a nestedPom
element to associate with this artifact.- Parameters:
pom
- the POM object
-
getPom
Returns the associated POM for this artifact, if any.- Returns:
- the POM object, or
null
if none is set
-
getArtifacts
Returns a list containing this single artifact.- Specified by:
getArtifacts
in interfaceArtifactContainer
- Returns:
- a singleton list with this artifact
-
execute
public void execute() throws org.apache.tools.ant.BuildExceptionRegisters this artifact in theProjectWorkspaceReader
for internal resolution.- Overrides:
execute
in classorg.apache.tools.ant.Task
- Throws:
org.apache.tools.ant.BuildException
-
toString
Returns a string representation of the artifact, showing its type and classifier.
-