How do I get Maven to use the correct repositories?

user284163 picture user284163 · Mar 2, 2010 · Viewed 160.7k times · Source

I have just checked out some projects and need to build them, however I installed Maven quite some time ago (6 months maybe?) and really haven't used it since - the pom.xml for the project I have doesn't have this "http://repo1.maven.org/myurlhere" anywhere in it - it has the absolute url where the Maven repo is for the project, but Maven is still trying to download from the general Maven repo:

Macintosh:trunk$ mvn clean install
[INFO] Scanning for projects...
Downloading: http://repo1.maven.org/url/project/project/x.x/project-x.x.pom
[INFO] Unable to find resource 'url.project:project:pom:x.x' in repository central (http://repo1.maven.org/)
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.

GroupId: url.project
ArtifactId: project
Version: x.x

Reason: Unable to download the artifact from any repository

  url.project:project:pom:x.x

from the specified remote repositories:
  central (http://repo1.maven.org/)

Can anyone help me with what I'm not doing right?
Basically, I have just checked the projects out from the command line, cd-ed into the directory and ran mvn clean install - nothing else.
Any help is greatly appreciated.

Answer

Pascal Thivent picture Pascal Thivent · Mar 2, 2010

the pom.xml for the project I have doesn't have this "http://repo1.maven.org/myurlhere" anywhere in it

All projects have http://repo1.maven.org/ declared as <repository> (and <pluginRepository>) by default. This repository, which is called the central repository, is inherited like others default settings from the "Super POM" (all projects inherit from the Super POM). So a POM is actually a combination of the Super POM, any parent POMs and the current POM. This combination is called the "effective POM" and can be printed using the effective-pom goal of the Maven Help plugin (useful for debugging).

And indeed, if you run:

mvn help:effective-pom

You'll see at least the following:

  <repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Maven Repository Switchboard</name>
      <url>http://repo1.maven.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Maven Plugin Repository</name>
      <url>http://repo1.maven.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>

it has the absolute url where the maven repo is for the project but maven is still trying to download from the general maven repo

Maven will try to find dependencies in all repositories declared, including in the central one which is there by default as we saw. But, according to the trace you are showing, you only have one repository defined (the central repository) or maven would print something like this:

Reason: Unable to download the artifact from any repository

  url.project:project:pom:x.x

from the specified remote repositories:
  central (http://repo1.maven.org/),
  another-repository (http://another/repository)

So, basically, maven is unable to find the url.project:project:pom:x.x because it is not available in central.

But without knowing which project you've checked out (it has maybe specific instructions) or which dependency is missing (it can maybe be found in another repository), it's impossible to help you further.