Thursday, 21 February 2008

Maven woes # 2923928923829: Maven metadata not reflecting what's on maven repository

(File under "Maven!!! GRRRRRR!")
Alternate longer title: What the hell is wrong with Maven and why do
they push out these SNAPSHOT plugins with releases to other SNAPSHOT
jars that don't even exist? As a matter of principle, should you
really be forcing non-release, snapshot software upon your users?
Here's what I was getting:
Error: Reason: Error getting POM for
'org.apache.maven.plugins:maven-archetype-plugin'
Unable to run Maven archetype because it is trying to download a
plugin that it can't get from the central Maven repository.
Turns out it's because of an inconsistency between the settings it has
in the location
\[username]\.m2\repository\org\apache\maven\plugins\maven-archetype-plugin\maven-metadata-central.xml
and what is actually on
http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-archetype-plugin/
C:\dev>mvn archetype:create -DgroupId=au.com.company.myapp -DartifactId=my-app
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] org.apache.maven.plugins: checking for updates from central
[INFO] artifact org.apache.maven.plugins:maven-archetype-plugin:
checking for updates from central
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).

Project ID: org.apache.maven.plugins:maven-archetype-plugin

Reason: Error getting POM for
'org.apache.maven.plugins:maven-archetype-plugin' from the repository:
Failed to resolve
artifact, possibly due to a repository list that is not appropriately
equipped for this artifact's metadata.
org.apache.maven.plugins:maven-archetype-plugin:pom:2.0-SNAPSHOT

from the specified remote repositories:
central (http://repo1.maven.org/maven2)
for project org.apache.maven.plugins:maven-archetype-plugin
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Wed Feb 20 17:35:46 EST 2008
[INFO] Final Memory: 1M/254M
[INFO] ------------------------------------------------------------------------

Solution:
1. Go into
\[user]\.m2\repository\org\apache\maven\plugins\maven-archetype-plugin\maven-metadata-central.xml
rename this file or delete it.
2. Get the file
http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-archetype-plugin/maven-metadata.xml
Download it to .m2\repository\org\apache\maven\plugins\maven-archetype-plugin\
and save it as maven-metadata-central.xml
3. Rerun the above process
mvn archetype:create -DgroupId=au.com.mydomain.myapp -DartifactId=my-app
now maven metadata is pointing to files that actually exist on the repository.
But the big questions here are:
Why is there a discrepancy at all? What other repositories could the
maven-metadata-central.xml be talking about if not the main
http://repo1.maven.org? Where did the maven-metadata-central.xml come
from anyway?
As a matter of design, why do I end up receiving - without my asking
for it - bleeding edge snapshot plugins? Shouldn't the policy be to
only use release versions?
Okay, maybe this argument is not really valid in this instance because
we are talking about the archetype-plugin. From the looks of what's on
the repository, it went out as 1.0-alpha-3 then to 1.0-alpha-5, then
1.0-alpha-7 - and now it's at 2.0-alpha-1. Good god, is this thing
*ever* going to get to an actual release number, one that doesn't have
greek letters after the .0?

Update on 6 Oct 2011:
NOTE: As commenters below have pointed out, the mixup normally occurs when you are - probably unknowingly - getting artifacts from both release and snapshot repositories.
The thing to remember is to make a distinction between release and snapshot repositories. The fact that you are pointing to a public repository is not enough. A repository obviously has to be public so that other people can access it. The question is: what types of artifacts are the repository providing? They may actually have both types.  

6 comments:

Glen Mazza said...

Thanks for taking the time to post this.

Gowtham said...

Hi Dude

even i am getting this error
when i run mvn archetype:create

failed to get the plugins and jars from repo1 , but still they had released

Thanks
Gowtham
http:\\ganesh.gowtham.googlepages.com

VerboseOutput said...

Hi,

had the same problem. I'm running my own installation of sonatype nexus as a caching proxy repository.

What I figured out about my specific configuration:

- nexus was configured to proxy *all* of the public repositories offered by https://repository.apache.org/, which also runs nexus.
- I had used the "public group" URL of that repository to configure my "Apache Repository" proxy, which is https://repository.apache.org/content/groups/public/
- This group includes repositories "Releases" AND Snapshots.
- The Snapshots Repository contains - guess what - version 2.0-beta5-SNAPSHOT of the archetype plugin (and ONLY this version, at the time of writing)
- re-configured my local nexus to proxy https://repository.apache.org/content/repositories/releases/ instead of the above URL
- now everything is fine.

Maybe this helps someone else with the same or a similar problem.

HINT HINT HINT: if you run into this problem, check your proxy settings. Don't accidentally access snapshot repositories.

Anonymous said...

WOW -- thanks for this post...saved me a ton of time. And thanks to VerboseOutput.

My Nexus instance was proxying the Jboss repo in order to get the latest versions of hibernate quickly. However it was using this URL:

http://repository.jboss.org/nexus/content/groups/public

which contains SNAPSHOTS -- a fact I did not know or realize. Now I use this URL:

https://repository.jboss.org/nexus/content/repositories/releases

And all is well.

aravind said...

Thanks so much. You made my day :)

snekse said...

Thanks for taking the time to post. As a noob to Maven, this would have taken me days to figure out.