Class LocalRepository
- All Implemented Interfaces:
Cloneable
This Ant DataType allows you to override the default local repository
(typically ~/.m2/repository) by specifying a custom directory to be used
for dependency resolution, artifact installation, or deployment.
The local repository directory is specified using the dir attribute.
This can be declared inline or via a shared reference using refid.
Usage Example:
<localRepository id="custom.repo" dir="target/local-repo"/>
<resolve>
<localRepo refid="custom.repo"/>
...
</resolve>
Attributes:
- dir — the directory to use as the local repository (required unless using
refid)
If this type is declared without a Task context,
it will automatically register itself with the current project via AntRepoSys.setLocalRepository(LocalRepository).
Typical Use Cases:
- Using an isolated local repository for reproducible builds
- Testing against a temporary or project-scoped repository
- Ensuring deployment and resolution do not affect the user's global Maven state
- 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
ConstructorsConstructorDescriptionConstructs a newLocalRepositorywithout an owning Ant task.LocalRepository(org.apache.tools.ant.Task task) Constructs a newLocalRepositorywith an owning Ant task. -
Method Summary
Modifier and TypeMethodDescriptiongetDir()Returns the directory to be used as the local Maven repository.protected LocalRepositorygetRef()Resolves this object if defined as a reference and verifies that it is aLocalRepositoryinstance.voidSets the directory to be used as the local Maven repository.voidsetProject(org.apache.tools.ant.Project project) Sets the Ant project context for thisLocalRepository.voidsetRefid(org.apache.tools.ant.types.Reference ref) Sets a reference to another<localRepository>definition.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
-
Constructor Details
-
LocalRepository
public LocalRepository()Constructs a newLocalRepositorywithout an owning Ant task.This constructor is typically used when the local repository is defined inline in the build script, allowing it to be automatically registered with the project.
-
LocalRepository
public LocalRepository(org.apache.tools.ant.Task task) Constructs a newLocalRepositorywith an owning Ant task.This constructor is used when the local repository is defined within a specific Ant task context, allowing it to be associated with that task.
- Parameters:
task- the Ant task that owns thisLocalRepository, ornullif not associated with a task
-
-
Method Details
-
setProject
public void setProject(org.apache.tools.ant.Project project) Sets the Ant project context for thisLocalRepository.In addition to the standard behavior of associating this data type with the Ant project, this method also automatically registers this
LocalRepositorywith the globalAntRepoSysinstance for the project, but only if no owningTaskwas provided.This automatic registration allows this local repository to become the default used for resolution and deployment tasks within the current build context.
- Overrides:
setProjectin classorg.apache.tools.ant.ProjectComponent- Parameters:
project- the Ant project to associate with this data type- See Also:
-
getRef
Resolves this object if defined as a reference and verifies that it is aLocalRepositoryinstance.- Returns:
- the referenced
LocalRepositoryinstance - Throws:
org.apache.tools.ant.BuildException- if the reference is invalid- See Also:
-
setRefid
public void setRefid(org.apache.tools.ant.types.Reference ref) Sets a reference to another<localRepository>definition.This allows the current
LocalRepositoryto act as an alias for another local repository definition declared elsewhere in the build script. When a reference is set, all other attributes (such asdir) must remain unset.Attempting to set this reference after the
dirattribute has already been specified will result in an error.- Overrides:
setRefidin classorg.apache.tools.ant.types.DataType- Parameters:
ref- the reference to anotherLocalRepository- Throws:
org.apache.tools.ant.BuildException- ifdiris already set- See Also:
-
getDir
Returns the directory to be used as the local Maven repository.If this
LocalRepositoryis defined as a reference (viarefid), the method delegates to the referenced instance.- Returns:
- the local repository directory, or
nullif not set - See Also:
-
setDir
Sets the directory to be used as the local Maven repository.This directory will be used in place of the default
~/.m2/repositoryfor tasks such as dependency resolution, artifact installation, and deployment.This method may not be used if this object is defined as a reference (i.e.,
refidis set). If the attributes are already configured, an exception will be thrown.- Parameters:
dir- the directory to use as the local repository- Throws:
org.apache.tools.ant.BuildException- if this instance is a reference or attributes are not allowed- See Also:
-