Class Dependencies

java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.types.DataType
org.apache.maven.resolver.internal.ant.types.Dependencies
All Implemented Interfaces:
Cloneable, DependencyContainer

public class Dependencies extends org.apache.tools.ant.types.DataType implements DependencyContainer
Container for multiple Maven dependencies in an Ant build script.

This Ant DataType represents a collection of Dependency elements. It is typically used within tasks like Resolve, CreatePom, Deploy, and Install to provide structured dependency information.

Usage Example (inline):


 <repo:resolve>
   <repo:dependencies>
     <repo:dependency groupId="org.apache.commons" artifactId="commons-lang3" version="3.18.0"/>
     <repo:dependency groupId="com.google.guava" artifactId="guava" version="32.0.2"/>
   </repo:dependencies>
   <path id="my.classpath"/>
 </resolve>
 

Usage Example (referenced):


 <dependencies id="compile.deps">
   <dependency groupId="org.slf4j" artifactId="slf4j-api" version="2.0.7"/>
 </dependencies>

 <resolve dependenciesRef="compile.deps">
   <path id="compile.classpath"/>
 </resolve>
 

Attributes:

  • id — optional Ant reference ID, allowing reuse in multiple tasks

Nested Elements:

  • <dependency> — defines a single Maven dependency (see Dependency)

Typical Use Cases:

  • Providing dependencies to resolution tasks like Resolve or CreatePom
  • Reusing a named set of dependencies across tasks via dependenciesRef

Behavior:

After being referenced by a task (e.g. via dependenciesRef), the container is evaluated and each contained <dependency> is passed to the task’s resolution or POM generation logic.
See Also:
  • Field Summary

    Fields inherited from class org.apache.tools.ant.types.DataType

    checked, ref

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

    description, location, project
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor for the Dependencies data type.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds another Dependencies container to this one.
    void
    Adds a single Dependency to this container.
    void
    Adds an Exclusion element to apply to all dependencies in this container.
    void
    addPom(Pom pom)
    Allows ant to add the pom element specified in the build file.
    Returns the list of contained DependencyContainer instances.
    Returns the list of exclusions applied to this container.
    Get the file attribute.
    Returns the Pom element if one was added to this container.
    protected Dependencies
    Resolves this object if defined as a reference and verifies that it is a Dependencies instance.
    void
    setFile(File file)
    Set the file attribute.
    void
    setPomRef(org.apache.tools.ant.types.Reference ref)
    Assigns a reference to a Pom element that defines the dependencies.
    void
    setRefid(org.apache.tools.ant.types.Reference ref)
    Sets the reference to another <dependencies> defined elsewhere.
    void
    validate(org.apache.tools.ant.Task task)
    Validates the container's internal structure and attributes.

    Methods inherited from class org.apache.tools.ant.types.DataType

    checkAttributesAllowed, checkChildrenAllowed, circularReference, clone, dieOnCircularReference, dieOnCircularReference, dieOnCircularReference, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getDataTypeName, getRefid, invokeCircularReferenceCheck, isChecked, isReference, noChildrenAllowed, pushAndInvokeCircularReferenceCheck, setChecked, tooManyAttributes, toString

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

    getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Dependencies

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

    • getRef

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

      public void validate(org.apache.tools.ant.Task task)
      Description copied from interface: DependencyContainer
      Validates the container's internal structure and attributes.

      This method is typically invoked by Ant tasks during execution to ensure that dependency definitions are well-formed, unambiguous, and do not conflict.

      Specified by:
      validate in interface DependencyContainer
      Parameters:
      task - the Ant task requesting validation, typically used for error context
    • setRefid

      public void setRefid(org.apache.tools.ant.types.Reference ref)
      Sets the reference to another <dependencies> defined elsewhere.

      This allows the current element to inherit the list of dependencies from the referenced element. No other children are allowed when this reference is set.

      Overrides:
      setRefid in class org.apache.tools.ant.types.DataType
      Parameters:
      ref - the reference to use
    • setFile

      public void setFile(File file)
      Set the file attribute.
      Parameters:
      file - the File to set
    • getFile

      public File getFile()
      Get the file attribute.
      Returns:
      the File.
    • addPom

      public void addPom(Pom pom)
      Allows ant to add the pom element specified in the build file. Only one pom element is allowed.
      Parameters:
      pom - the Pom element to add.
    • getPom

      public Pom getPom()
      Returns the Pom element if one was added to this container.
      Returns:
      the Pom or null if none
    • setPomRef

      public void setPomRef(org.apache.tools.ant.types.Reference ref)
      Assigns a reference to a Pom element that defines the dependencies.

      This is an alternative to specifying nested <dependency> elements directly.

      Parameters:
      ref - the reference to a Pom element
    • addDependency

      public void addDependency(Dependency dependency)
      Adds a single Dependency to this container.
      Parameters:
      dependency - the dependency to add
    • addDependencies

      public void addDependencies(Dependencies dependencies)
      Adds another Dependencies container to this one.

      Allows for nesting of dependency collections. This can be useful when grouping dependencies by purpose or configuration.

      Parameters:
      dependencies - another Dependencies object to merge
      Throws:
      org.apache.tools.ant.BuildException - if attempting to add self or if usage conflicts with other sources
    • getDependencyContainers

      public List<DependencyContainer> getDependencyContainers()
      Returns the list of contained DependencyContainer instances. This may include Dependency elements or nested Dependencies.
      Returns:
      list of dependency containers
    • addExclusion

      public void addExclusion(Exclusion exclusion)
      Adds an Exclusion element to apply to all dependencies in this container.

      Exclusions can be used to omit specific transitive dependencies.

      Parameters:
      exclusion - the exclusion to apply
    • getExclusions

      public List<Exclusion> getExclusions()
      Returns the list of exclusions applied to this container.
      Returns:
      list of Exclusion objects