Repositories Maven


Artifact Repositories

In Maven, a repository stores many types of build artifacts and dependencies. Local and remote repositories are the two types of repositories:

1. The local repository is a folder on the machine that Maven is installed on. It stores temporary build artifacts and caches remote downloads that you haven't yet released.

Any other sort of repository that can be accessed via various protocols, such as file:/ and https://, is referred to as a remote repository. These repositories could be remote repositories set up by third parties to make their artifacts available for download (repo.maven.apache.org). Internal repositories put up on a file or HTTP server within your firm used to distribute private assets between development teams and releases are examples of "remote" repositories.

Scripts can run on either side or be synchronized for offline use because local and remote repositories are constructed the same way. The layout of the repositories, on the other hand, is transparent to the Maven user.

Using Repositories

You shouldn't need to do anything with the local repository regularly, except clean it out if you're running low on storage space (or erase it if you are willing to download everything again).

They are used to download and upload remote repositories (if you have permission to do so).

Downloading from a Remote Repository

A project declares a dependency is not existing in the local repository, which causes Maven to download it (or for a SNAPSHOT, when the remote repository contains a newer one). Maven will download from the central repository by default.

You can override this by specifying a mirror, as described in Using Mirrors for Repositories.

You can set this in your settings.xml file to use a specific mirror globally. However, it is normal for a project's pom.xml to customize the repository, and your choice will take precedence. Check that you haven't overridden the remote repository if dependencies aren't discovered.

See Dependency Mechanism for additional information on dependencies.

Using Mirrors for the Central Repository

There are multiple geographically spread official Central repositories. To use one or more mirrors, make adjustments to your settings.xml file. The guide Using Mirrors for Repositories has instructions on how to do this.

Offline Construction

You can use the offline switch on the CLI to build your projects if you are temporarily disconnected from the internet: mvn -o package.

Many plugins respect the offline option and don't execute any internet-related tasks. Resolving Javadoc links and link checking the webpage are two instances.

Uploading to a Remote Repository

While any form of the remote repository can be used in this way, you must have the authorization to do so. See Repository Center have someone upload to the Central Maven repository.

Internal Repositories

While using Maven, connecting to the internet to download dependencies is not acceptable, especially in a business context, for security, speed, or bandwidth concerns. As a result, it's a good idea to set up an internal repository where you can keep a copy of artifacts and publish private artifacts.

A file:/ URL can be used to obtain an internal repository, which can then be posted using SCP, FTP, or a file copy.

This repository is unusual in Maven's eyes: it's just another remote repository with artifacts to download to a user's local cache and serves as a publishing destination for artifact releases.

You might also want to share the repository server with the project sites you've created. See Developing a Site for additional information on creating and deploying sites.

Setting up the Internal Repository

To create an internal repository, all you need is a location for it and the ability to copy essential artifacts there using the same layout as a remote repository like repo.maven.apache.org.

Scraping or rsync:/ a full copy of central is not suggested because there is a lot of data there, and doing it will get you banned. You can run your internal repository's server with software like those mentioned on the Repository Management page, download artifacts from the internet as needed, and then store them in your internal repository for subsequent download.

Other alternatives include manually downloading and vetting releases before copying them to the internal repository or having Maven download releases for a user and manually uploading the vetted artifacts to the internal repository. This is the sole option for artifacts where the licensing prohibits automated distribution, such as some J2EE JARs issued by Sun. For further details, see the document Guide to Coping with SUN JARs.

It's worth noting that Maven plans to improve support for such features in the future, including click-through licensing during download and signature verification.

Using the Internal Repository

It's easy to use the internal repository. Simply update the following to include a repositories element:

<project> ... <repositories> <repository> <id>my-internal-site</id> <url>https://myserver/repo</url> </repository> </repositories> ... </project>

If your internal repository requires authentication, you can specify login information in your settings file using the id element.

Deploying to the Internal Repository

The ability to publish your private releases is essential to have one or more internal repositories.

You'll need access to the repository through SCP, SFTP, FTP, WebDAV, or the filesystem to publish to it. The many carts connect the various areas, and some wagons may need to be added to your build as an add-on.