Class AntRepoSys
java.lang.Object
org.apache.maven.resolver.internal.ant.AntRepoSys
Central utility for managing Maven repository system configuration and sessions within Ant builds.
This class handles the lifecycle of a RepositorySystem
and provides access to its components,
such as mirror selectors, proxy selectors, authentication, session management, and settings resolution.
It also provides methods for resolving dependencies, installing, and deploying artifacts.
An instance of this class is typically retrieved via getInstance(Project)
and registered under
a predefined reference ID for reuse throughout the Ant build.
This class supports merging default and user-defined repositories and processing settings from
settings.xml
files, including mirrors, proxies, and server credentials.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addAuthentication
(Authentication authentication) Registers anAuthentication
instance to be used during authentication selection.void
Registers aMirror
to be included in the mirror selector.void
Registers aProxy
to be considered when building the proxy selector.org.eclipse.aether.collection.CollectResult
collectDependencies
(org.apache.tools.ant.Task task, Dependencies dependencies, LocalRepository localRepository, RemoteRepositories remoteRepositories) Performs dependency resolution by collecting transitive dependencies for the given configuration.void
deploy
(org.apache.tools.ant.Task task, Pom pom, Artifacts artifacts, RemoteRepository releaseRepository, RemoteRepository snapshotRepository) Deploys the specified artifacts to the configured remote repository (release or snapshot).Returns the defaultPom
, if set.static AntRepoSys
getInstance
(org.apache.tools.ant.Project project) Returns the singleton instance ofAntRepoSys
associated with the given AntProject
.org.eclipse.aether.RepositorySystemSession
getSession
(org.apache.tools.ant.Task task, LocalRepository localRepo) Creates and returns a newRepositorySystemSession
for the given task and local repository.org.eclipse.aether.RepositorySystem
Returns theRepositorySystem
used for dependency resolution and repository operations.void
Installs the specified artifacts to the local Maven repository.org.apache.maven.model.Model
loadModel
(org.apache.tools.ant.Task task, File pomFile, boolean local, RemoteRepositories remoteRepositories) Resolves aModel
from apom.xml
file, optionally validating it as a local or remote model.void
setDefaultPom
(Pom pom) Sets the defaultPom
used for artifact operations when none is explicitly provided.void
setGlobalSettings
(File file) Sets the path to the globalsettings.xml
file.void
setLocalRepository
(LocalRepository localRepository) Sets the local repository configuration.void
setUserSettings
(File file) Sets the path to the user-levelsettings.xml
file.
-
Method Details
-
getInstance
Returns the singleton instance ofAntRepoSys
associated with the given AntProject
. Registers a new instance if not already present.- Parameters:
project
- the current Ant project- Returns:
- the
AntRepoSys
instance
-
getSystem
public org.eclipse.aether.RepositorySystem getSystem()Returns theRepositorySystem
used for dependency resolution and repository operations.- Returns:
- the repository system instance
-
getSession
public org.eclipse.aether.RepositorySystemSession getSession(org.apache.tools.ant.Task task, LocalRepository localRepo) Creates and returns a newRepositorySystemSession
for the given task and local repository. Configures authentication, mirrors, proxies, offline mode, and repository listeners.- Parameters:
task
- the invoking Ant task (used for logging and listeners)localRepo
- optional local repository configuration- Returns:
- a configured repository system session
-
setUserSettings
Sets the path to the user-levelsettings.xml
file. If changed, forces reloading of settings.- Parameters:
file
- the user settings file
-
setGlobalSettings
Sets the path to the globalsettings.xml
file. If changed, forces reloading of settings.- Parameters:
file
- the global settings file
-
addProxy
Registers aProxy
to be considered when building the proxy selector.- Parameters:
proxy
- the proxy configuration
-
addMirror
Registers aMirror
to be included in the mirror selector.- Parameters:
mirror
- the mirror configuration
-
addAuthentication
Registers anAuthentication
instance to be used during authentication selection.- Parameters:
authentication
- the authentication configuration
-
setLocalRepository
Sets the local repository configuration.- Parameters:
localRepository
- the local repository configuration
-
loadModel
public org.apache.maven.model.Model loadModel(org.apache.tools.ant.Task task, File pomFile, boolean local, RemoteRepositories remoteRepositories) Resolves aModel
from apom.xml
file, optionally validating it as a local or remote model.- Parameters:
task
- the Ant task contextpomFile
- the POM filelocal
- whether to load the model in strict/local moderemoteRepositories
- optional custom remote repositories- Returns:
- the effective Maven model
- Throws:
org.apache.tools.ant.BuildException
- if the POM cannot be loaded or resolved
-
setDefaultPom
Sets the defaultPom
used for artifact operations when none is explicitly provided.- Parameters:
pom
- the default POM
-
getDefaultPom
Returns the defaultPom
, if set.- Returns:
- the default POM or
null
-
collectDependencies
public org.eclipse.aether.collection.CollectResult collectDependencies(org.apache.tools.ant.Task task, Dependencies dependencies, LocalRepository localRepository, RemoteRepositories remoteRepositories) Performs dependency resolution by collecting transitive dependencies for the given configuration.- Parameters:
task
- the Ant task contextdependencies
- the root dependencieslocalRepository
- optional local repository overrideremoteRepositories
- optional custom remote repositories- Returns:
- the result of dependency collection
- Throws:
org.apache.tools.ant.BuildException
- if the dependency collection fails
-
install
Installs the specified artifacts to the local Maven repository.- Parameters:
task
- the Ant task contextpom
- the associated POM metadataartifacts
- the artifacts to install- Throws:
org.apache.tools.ant.BuildException
- if the installation fails
-
deploy
public void deploy(org.apache.tools.ant.Task task, Pom pom, Artifacts artifacts, RemoteRepository releaseRepository, RemoteRepository snapshotRepository) Deploys the specified artifacts to the configured remote repository (release or snapshot).- Parameters:
task
- the Ant task contextpom
- the associated POM metadataartifacts
- the artifacts to deployreleaseRepository
- the repository for release artifactssnapshotRepository
- the repository for snapshot artifacts- Throws:
org.apache.tools.ant.BuildException
- if the deployment fails
-