Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force Maven to download maven-metadata.xml from the central repository?

What I want to do is to force Maven to download the 'maven-metadata.xml' for each artifact that I have in my local repository.

The default Maven behaviour is to download only metadata from remote repositories (see this question).

Why I want to do that:

Currently I have a remote repository running in a build machine. By remote repository I mean a directory located in the build machine that contains all dependencies that I need to build my Maven projects. Note that I'm not using a repository manager like Nexus, the repository is just a copy of a local repository that I have uploaded to my build machine.

However, since my local repository did not contain the 'maven-metadata.xml' files, these metadata files are also missing in the build machine repository. If I could retrieve the metadata files from the central repository, then it would be possible to upload a working remote repository to my build machine.

like image 624
Alceu Costa Avatar asked Aug 13 '09 16:08

Alceu Costa


People also ask

How do I force Maven to download dependencies from remote repository?

We can use -U/--update-snapshots flag when building a maven project to force maven to download dependencies from the remote repository. Here, -U,--update-snapshots : Forces a check for missing releases and updated snapshots on remote repositories.

Why is Maven downloading the Maven metadata XML every time?

Maven does this because your dependency is in a SNAPSHOT version and maven has no way to detect any changes made to that snapshot version in the repository. Release your artifact and change the version in pom. xml to that version and maven will no longer fetch the metadata file.


1 Answers

You don't want to get the metadata from the public repositories, it will contain all the versions available of a given artifact, whereas your repository will have some subset of the releases.

It's worth pointing out that you really would be better off with a repository manager. The following steps allow you to generate your artifact metadata once. But if your needs change, you'll have to repeat the process or update the files manually, so why not just use a manager? Nexus can run standalone and has a very small footprint.


Even if you're not planning on using Nexus for a repository manager, you can still use it to generate your metadata.

  1. First install Nexus.
  2. Locate the nexus work directory (by default ${user.home}/sonatype-work.
  3. Copy your local repository contents to the nexus-work/releases sub-directory.
  4. Start Nexus and connect to the Nexus home page in the browser (by default http://localhost:8081/nexus)
  5. Log in using the admin account (password admin123)
  6. Click on the repositories link on the left hand side.
  7. Select the Releases repository, right-click and click Rebuild Metadata

In a few moments you should have the metadata generated for all the artifacts. You can then copy them to wherever you need them to be and uninstall Nexus.

like image 185
Rich Seller Avatar answered Sep 17 '22 02:09

Rich Seller