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

public class Exclusion extends org.apache.tools.ant.types.DataType
Represents a Maven dependency exclusion in an Ant build script.

This type is used within a Dependency to specify transitive dependencies that should be excluded when the parent dependency is resolved. Exclusions help avoid unwanted or conflicting artifacts that would otherwise be pulled in transitively.

Usage Example:


 <dependency groupId="org.example" artifactId="example-lib" version="1.0.0">
   <exclusion groupId="commons-logging" artifactId="commons-logging"/>
 </dependency>
 

Attributes:

  • groupId — the group ID of the dependency to exclude (required)
  • artifactId — the artifact ID of the dependency to exclude (required)

Typical Use Cases:

  • Preventing known problematic or unwanted transitive dependencies
  • Ensuring consistency by excluding duplicates or old versions
  • Controlling the effective dependency graph in complex builds

The exclusion applies only to the specific dependency in which it is declared, and does not affect other dependencies that may bring in the same artifact transitively.

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 Exclusion.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the artifactId of the dependency to exclude.
    Returns the classifier of the dependency to exclude, if specified.
    Returns the extension (file type) of the dependency to exclude.
    Returns the groupId of the dependency to exclude.
    protected Exclusion
    Resolves this object if defined as a reference and verifies that it is a Exclusion instance.
    void
    setArtifactId(String artifactId)
    Sets the artifactId of the dependency to exclude.
    void
    setClassifier(String classifier)
    Sets the classifier of the dependency to exclude.
    void
    setCoords(String coords)
    Sets the exclusion coordinates using a compact colon-separated format.
    void
    setExtension(String extension)
    Sets the extension (file type) of the dependency to exclude.
    void
    setGroupId(String groupId)
    Sets the groupId of the dependency to exclude.
    void
    setRefid(org.apache.tools.ant.types.Reference ref)
     
    void
    validate(org.apache.tools.ant.Task task)
    Validates that the required attributes of this exclusion are set.

    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

    • Exclusion

      public Exclusion()
      Default constructor for Exclusion.

      This constructor is used when the Exclusion is created as a nested element in an Ant task.

  • Method Details

    • getRef

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

      public void validate(org.apache.tools.ant.Task task)
      Validates that the required attributes of this exclusion are set.

      Specifically, both groupId and artifactId must be provided for the exclusion to be valid. If either is missing, this method throws a BuildException, indicating a configuration error in the Ant build script.

      This method is typically called during task execution to ensure that the exclusion is well-formed before it is passed to the underlying Maven model.

      Parameters:
      task - the Ant task context used for error reporting
      Throws:
      org.apache.tools.ant.BuildException - if groupId or artifactId is not set
      See Also:
    • setRefid

      public void setRefid(org.apache.tools.ant.types.Reference ref)
      Overrides:
      setRefid in class org.apache.tools.ant.types.DataType
    • getGroupId

      public String getGroupId()
      Returns the groupId of the dependency to exclude.

      This is a required attribute that identifies the group (organization or project) of the transitive dependency to be excluded. The exclusion will only be valid if both groupId and artifactId are specified.

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

      public void setGroupId(String groupId)
      Sets the groupId of the dependency to exclude.

      The groupId identifies the group or organization that provides the transitive dependency you want to exclude. This is a required attribute for a valid exclusion.

      The value may include Ant properties (e.g., ${excluded.groupId}), which will be resolved at runtime using the current Ant project context.

      Parameters:
      groupId - the group ID of the excluded dependency
      See Also:
    • getArtifactId

      public String getArtifactId()
      Returns the artifactId of the dependency to exclude.

      This is a required attribute that specifies the artifact within the given groupId that should be excluded from transitive dependency resolution.

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

      public void setArtifactId(String artifactId)
      Sets the artifactId of the dependency to exclude.

      The artifactId identifies the specific artifact (e.g., library or module name) to exclude from the transitive dependency graph. This is a required attribute and must be used in conjunction with groupId.

      The value may include Ant properties (e.g., ${excluded.artifactId}), which will be resolved at runtime.

      Parameters:
      artifactId - the artifact ID of the excluded dependency
      See Also:
    • getClassifier

      public String getClassifier()
      Returns the classifier of the dependency to exclude, if specified.

      The classifier distinguishes artifacts that are built from the same source but differ in content, such as sources, javadoc, or platform-specific variants.

      If no classifier is specified, this method returns null, and the exclusion applies to all classifiers of the specified groupId:artifactId.

      Returns:
      the classifier of the excluded dependency, or null if not set
      See Also:
    • setClassifier

      public void setClassifier(String classifier)
      Sets the classifier of the dependency to exclude.

      The classifier distinguishes a variant of the artifact with the same groupId, artifactId, and type, such as sources or javadoc. This is an optional attribute; if omitted, the exclusion will match all classifiers.

      The value may include Ant properties (e.g., ${excluded.classifier}), which will be resolved at runtime using the Ant project context.

      Parameters:
      classifier - the classifier to match for exclusion
      See Also:
    • getExtension

      public String getExtension()
      Returns the extension (file type) of the dependency to exclude.

      If this exclusion is a reference to another one (via refid), the extension will be delegated to the referenced exclusion.

      If no extension has been explicitly set, this method returns a wildcard value (usually "*"), indicating that the exclusion applies to all extensions for the given coordinates.

      Returns:
      the extension to match for exclusion, or a wildcard if not explicitly set
      See Also:
    • setExtension

      public void setExtension(String extension)
      Sets the extension (file type) of the dependency to exclude.

      The extension typically corresponds to the artifact's file type, such as jar, pom, zip, etc. If not set, a wildcard value will be used to match any extension.

      This method may only be called if the exclusion is not defined as a reference (i.e., refid is not set). If this exclusion is a reference, or if the extension has already been set, this method will throw an exception.

      Parameters:
      extension - the file extension to exclude
      Throws:
      org.apache.tools.ant.BuildException - if this exclusion is a reference or the extension is already set
      See Also:
    • setCoords

      public void setCoords(String coords)
      Sets the exclusion coordinates using a compact colon-separated format.

      This is a convenience method that allows you to specify the exclusion as a single string in the format:

       groupId[:artifactId[:extension[:classifier]]]
       

      Any omitted segments are automatically set to "*" (wildcard), which matches all values for that component. For example:

      • com.example → excludes all artifacts from com.example
      • com.example:my-lib → excludes all extensions/classifiers of my-lib
      • com.example:my-lib:jar:sources → excludes only my-lib-*.jar:sources

      This method may only be used if no individual attributes (such as groupId, artifactId, extension, or classifier) have been set, and the exclusion is not a reference (i.e., refid is not set).

      Parameters:
      coords - the exclusion coordinates in colon-separated format
      Throws:
      org.apache.tools.ant.BuildException - if the exclusion is a reference, if any individual coordinate attributes are already set, or if the format is invalid
      See Also: