(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.