Class LocalRepository

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

public class LocalRepository extends org.apache.tools.ant.types.DataType
Represents a custom local Maven repository location in an Ant build script.

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, ref

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

    description, location, project
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new LocalRepository without an owning Ant task.
    LocalRepository(org.apache.tools.ant.Task task)
    Constructs a new LocalRepository with an owning Ant task.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the directory to be used as the local Maven repository.
    protected LocalRepository
    Resolves this object if defined as a reference and verifies that it is a LocalRepository instance.
    void
    setDir(File dir)
    Sets the directory to be used as the local Maven repository.
    void
    setProject(org.apache.tools.ant.Project project)
    Sets the Ant project context for this LocalRepository.
    void
    setRefid(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, toString

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

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

    Methods inherited from class java.lang.Object

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

    • LocalRepository

      public LocalRepository()
      Constructs a new LocalRepository without 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 new LocalRepository with 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 this LocalRepository, or null if not associated with a task
  • Method Details

    • setProject

      public void setProject(org.apache.tools.ant.Project project)
      Sets the Ant project context for this LocalRepository.

      In addition to the standard behavior of associating this data type with the Ant project, this method also automatically registers this LocalRepository with the global AntRepoSys instance for the project, but only if no owning Task was provided.

      This automatic registration allows this local repository to become the default used for resolution and deployment tasks within the current build context.

      Overrides:
      setProject in class org.apache.tools.ant.ProjectComponent
      Parameters:
      project - the Ant project to associate with this data type
      See Also:
    • getRef

      protected LocalRepository getRef()
      Resolves this object if defined as a reference and verifies that it is a LocalRepository instance.
      Returns:
      the referenced LocalRepository instance
      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 LocalRepository to act as an alias for another local repository definition declared elsewhere in the build script. When a reference is set, all other attributes (such as dir) must remain unset.

      Attempting to set this reference after the dir attribute has already been specified will result in an error.

      Overrides:
      setRefid in class org.apache.tools.ant.types.DataType
      Parameters:
      ref - the reference to another LocalRepository
      Throws:
      org.apache.tools.ant.BuildException - if dir is already set
      See Also:
    • getDir

      public File getDir()
      Returns the directory to be used as the local Maven repository.

      If this LocalRepository is defined as a reference (via refid), the method delegates to the referenced instance.

      Returns:
      the local repository directory, or null if not set
      See Also:
    • setDir

      public void setDir(File dir)
      Sets the directory to be used as the local Maven repository.

      This directory will be used in place of the default ~/.m2/repository for 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., refid is 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: