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

4

7

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.

Seaddon answered 13/8, 2009 at 16:57 Comment(1)
I'm not clear exactly what you mean, or why you need to do this. Can you explain what you're trying to achieve?Tallou
T
9

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.

Tallou answered 13/8, 2009 at 20:14 Comment(4)
I agree, he needs shared repos for the build and local machines. There is no way he is going to keep the two copies of the metadata in syncVerger
The solution worked for me. Also, thanks to sal for the advice, but what I really need is a workaround for the problem, even though I understand that that's not the ideal solution...Seaddon
This does not answer the question.Suckling
The question was not about why you should or should not download the metadata. It's about HOW to do it.Matriculation
V
4

The default repositories are defined in the super pom.xml that all poms inherit from by default.

If by local you mean you want to only use ~/.m2/repos/* then work in offline mode. Add <offline>true</offline> to your settings.xml

If by local you mean your local server, you could install a repository manager like Nexus, modify your settings file to use nexus under "mirrors" like this:

<mirror>
  <id>central-proxy</id>
  <mirrorOf>central</mirrorOf>
  <url>my/local/nexus/server</url>
</mirror>

And disable remote repositories you don't want in Nexus.

Verger answered 13/8, 2009 at 17:7 Comment(3)
By local I mean ~/.m2/repos/* , however if use either the <offline> tag or the -o flag Maven will not download the 'maven-metada.xml' files that I want.Seaddon
I think you need to have different build and deploy repos for you remote machine. Have the build machine use a local maven repo for build then another place on disk for deployment. Use some server to make that 2nd repository visible. You'll also want your local builds deployed to that 3rd repos. The metadata will sort itself out in that situation.Verger
what & why <mirrorOf> ? above description is helping me.Haemostat
B
1

One thing I found is someone was doing an initial search of jarvana and had placed this within the pom, causing a metadata error message to occur. This ...

   <!-- <repository>
        <id>jarvana</id>
        <url>http://www.jarvana.com/jarvana/browse/</url>
    </repository> -->

..fixed it and the error went away.

Bullshit answered 4/2, 2011 at 23:21 Comment(0)
S
0

Repository manager is great but I don't want install and run it on my laptop. I just want to save resource. So, my solution is below:

  1. install repository as artifactory (https://www.jfrog.com/artifactory)
  2. run materialize thru this server (localhost:8081)
  3. run materialize thru remote server (center.maven.org)
  4. download cache content of artifactory
  5. merger to folder: folder download from step 4 and folder at ~/.m2/repository.

Now I have a repository offline with full content (binary, source, xml, md5, sha1)

Sideboard answered 10/1, 2016 at 14:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.