Class Exclusion
- All Implemented Interfaces:
Cloneable
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, refFields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns theartifactIdof 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 thegroupIdof the dependency to exclude.protected ExclusiongetRef()Resolves this object if defined as a reference and verifies that it is aExclusioninstance.voidsetArtifactId(String artifactId) Sets theartifactIdof the dependency to exclude.voidsetClassifier(String classifier) Sets the classifier of the dependency to exclude.voidSets the exclusion coordinates using a compact colon-separated format.voidsetExtension(String extension) Sets the extension (file type) of the dependency to exclude.voidsetGroupId(String groupId) Sets thegroupIdof the dependency to exclude.voidsetRefid(org.apache.tools.ant.types.Reference ref) voidvalidate(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, toStringMethods inherited from class org.apache.tools.ant.ProjectComponent
getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject
-
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
Resolves this object if defined as a reference and verifies that it is aExclusioninstance.- Returns:
- the referenced
Exclusioninstance - 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
groupIdandartifactIdmust be provided for the exclusion to be valid. If either is missing, this method throws aBuildException, 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- ifgroupIdorartifactIdis not set- See Also:
-
setRefid
public void setRefid(org.apache.tools.ant.types.Reference ref) - Overrides:
setRefidin classorg.apache.tools.ant.types.DataType
-
getGroupId
Returns thegroupIdof 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
groupIdandartifactIdare specified.- Returns:
- the group ID of the excluded dependency, or
nullif not set - See Also:
-
setGroupId
Sets thegroupIdof the dependency to exclude.The
groupIdidentifies 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
Returns theartifactIdof the dependency to exclude.This is a required attribute that specifies the artifact within the given
groupIdthat should be excluded from transitive dependency resolution.- Returns:
- the artifact ID of the excluded dependency, or
nullif not set - See Also:
-
setArtifactId
Sets theartifactIdof the dependency to exclude.The
artifactIdidentifies 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 withgroupId.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
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 specifiedgroupId:artifactId.- Returns:
- the classifier of the excluded dependency, or
nullif not set - See Also:
-
setClassifier
Sets the classifier of the dependency to exclude.The classifier distinguishes a variant of the artifact with the same
groupId,artifactId, andtype, such assourcesorjavadoc. 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
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
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.,
refidis 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
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 fromcom.examplecom.example:my-lib→ excludes all extensions/classifiers ofmy-libcom.example:my-lib:jar:sources→ excludes onlymy-lib-*.jar:sources
This method may only be used if no individual attributes (such as
groupId,artifactId,extension, orclassifier) have been set, and the exclusion is not a reference (i.e.,refidis 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:
-