如何让 Maven 使用正确的存储库?

发布于 2024-08-24 05:32:22 字数 1123 浏览 6 评论 0原文

我刚刚检查了一些项目并需要构建它们,但是我很久以前就安装了 Maven(也许是 6 个月?),并且从那以后就没有真正使用过它 - 项目的 pom.xml我在其中的任何地方都没有这个“http://repo1.maven.org/myurlhere” - 它具有 Maven 存储库所在项目的绝对 url,但 Maven 仍在尝试从通用 Maven 存储库下载:

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/)

任何人都可以帮助我解决我做错的事情吗?
基本上,我刚刚从命令行检查了项目,cd-ed 进入目录并运行 mvn clean install - 没有其他。
非常感谢任何帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

離殇 2024-08-31 05:32:22

我项目的 pom.xml 中的任何地方都没有这个“https://repo1.maven.org/myurlhere”

所有项目都有默认的https://repo1.maven.org/ 声明为 (和 )默认情况下。这个存储库称为中央存储库,它像其他默认设置一样从“Super POM”继承(所有项目都继承自Super POM)。所以 POM 实际上是 Super POM、任何父 POM 和当前 POM 的组合。这种组合称为“有效的 POM”,可以使用 Maven 帮助插件的 ​​effective-pom 目标进行打印(对于调试很有用)。

事实上,如果你运行:

mvn help:effective-pom

你至少会看到以下内容:

  <repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Maven Repository Switchboard</name>
      <url>https://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>https://repo1.maven.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>

它具有项目的 Maven 存储库所在的绝对 URL,但 Maven 仍在尝试从通用 Maven 存储库下载

Maven 将尝试在声明的所有存储库中查找依赖项,包括在 central 存储库中正如我们所见,默认情况下。但是,根据您显示的跟踪,您只定义了 一个 存储库(中央存储库),否则 maven 会打印如下内容:

Reason: Unable to download the artifact from any repository

  url.project:project:pom:x.x

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

所以,基本上,maven 无法找到 url .project:project:pom:xx 因为它在central中不可用。

但是,如果不知道您签出了哪个项目(它可能有具体的说明)或缺少哪个依赖项(它可能可以在另一个存储库中找到),就不可能为您提供进一步的帮助。

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

All projects have default https://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>https://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>https://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 (https://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.

煞人兵器 2024-08-31 05:32:22

默认情况下,Maven 将始终在官方 Maven 存储库中查找,即 http://repo1.maven.org

当 Maven 尝试构建项目时,它将在您的本地存储库中查找(默认情况下 ~/.m2/repository 但您可以通过更改 来配置它~/.m2/settings.xml 中的值)来查找 pom.xml 中定义的任何依赖项、插件或报告。如果在本地存储库中找不到足够的工件,它将在所有配置的外部存储库中查找,从默认存储库 http: //repo1.maven.org

您可以通过在 settings.xml 文件中设置镜像来配置 Maven 以避免使用此默认存储库:

<mirrors>
    <mirror>
        <id>repoMirror</id>
        <name>Our mirror for Maven repository</name>
        <url>http://the/server/</url>
        <mirrorOf>*</mirrorOf>
    </mirror>
</mirrors>

这样,就不用联系 http://repo1.maven.org, Maven 将联系您的企业存储库(本例中为 http://the/server)。

如果您想添加另一个存储库,可以在 settings.xml 文件中定义一个新存储库:

<profiles>
    <profile>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <repositories>
            <repository>
                <id>foo.bar</id>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
                <url>http://new/repository/server</url>
            </repository>
        </repositories>

您可以看到完整的 settings.xml 模型 此处

关于clean过程,您可以要求Maven离线运行它。在这种情况下,Maven 将不会尝试访问任何外部存储库:

mvn -o clean 

By default, Maven will always look in the official Maven repository, which is http://repo1.maven.org.

When Maven tries to build a project, it will look in your local repository (by default ~/.m2/repository but you can configure it by changing the <localRepository> value in your ~/.m2/settings.xml) to find any dependency, plugin or report defined in your pom.xml. If the adequate artifact is not found in your local repository, it will look in all external repositories configured, starting with the default one, http://repo1.maven.org.

You can configure Maven to avoid this default repository by setting a mirror in your settings.xml file:

<mirrors>
    <mirror>
        <id>repoMirror</id>
        <name>Our mirror for Maven repository</name>
        <url>http://the/server/</url>
        <mirrorOf>*</mirrorOf>
    </mirror>
</mirrors>

This way, instead of contacting http://repo1.maven.org, Maven will contact your entreprise repository (http://the/server in this example).

If you want to add another repository, you can define a new one in your settings.xml file:

<profiles>
    <profile>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <repositories>
            <repository>
                <id>foo.bar</id>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
                <url>http://new/repository/server</url>
            </repository>
        </repositories>

You can see the complete settings.xml model here.

Concerning the clean process, you can ask Maven to run it offline. In this case, Maven will not try to reach any external repositories:

mvn -o clean 
风渺 2024-08-31 05:32:22

tl;dr

所有 Maven POM 都继承自基础 超级 POM< /strong>
下面的代码片段是 Maven 3.5.4 的 Super POM 的一部分。

  <repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>

tl;dr

All maven POMs inherit from a base Super POM.
The snippet below is part of the Super POM for Maven 3.5.4.

  <repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>
时光匆匆的小流年 2024-08-31 05:32:22

我认为您在这里错过的是:

https://maven.apache.org/settings。 html#服务器

用于下载和部署的存储库由 POM 的 repositories 和 distributionManagement 元素定义。但是,某些设置(例如用户名和密码)不应与 pom.xml 一起分发。此类信息应存在于构建服务器的 settings.xml 中。

这是使用自定义存储库的首选方式。因此,可能发生的情况是该存储库的 url 位于构建服务器的 settings.xml 中。

一旦您掌握了 url 和凭据,您就可以将它们放入您的计算机中:~/.m2/settings.xml,如下所示:

<settings ...> 

        .
        .
        .
        <servers>
            <server>
              <id>internal-repository-group</id>
              <username>YOUR-USERNAME-HERE</username>
              <password>YOUR-PASSWORD-HERE</password>
            </server>
        </servers>
</settings>

编辑:

然后您需要将此存储库引用到项目 POM 中。 ID internal-repository-group 可以在每个项目中使用。您可以在设置 xml 中使用不同的 ID 设置多个存储库和凭据设置。

这种方法的优点是可以共享项目而无需担心凭据,并且不必在每个项目中提及凭据。

以下是使用“internal-repository-group”的项目示例 pom

<repositories>
    <repository>
        <id>internal-repository-group</id>
        <name>repo-name</name>
        <url>http://project.com/yourrepourl/</url>
        <layout>default</layout>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
        </releases>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
        </snapshots>
    </repository>
</repositories>

I think what you have missed here is this:

https://maven.apache.org/settings.html#Servers

The repositories for download and deployment are defined by the repositories and distributionManagement elements of the POM. However, certain settings such as username and password should not be distributed along with the pom.xml. This type of information should exist on the build server in the settings.xml.

This is the prefered way of using custom repos. So probably what is happening is that the url of this repo is in settings.xml of the build server.

Once you get hold of the url and credentials, you can put them in your machine here: ~/.m2/settings.xml like this:

<settings ...> 

        .
        .
        .
        <servers>
            <server>
              <id>internal-repository-group</id>
              <username>YOUR-USERNAME-HERE</username>
              <password>YOUR-PASSWORD-HERE</password>
            </server>
        </servers>
</settings>

EDIT:

You then need to refer this repository into project POM. The id internal-repository-group can be used in every project. You can setup multiple repos and credentials setting using different IDs in settings xml.

The advantage of this approach is that project can be shared without worrying about the credentials and don't have to mention the credentials in every project.

Following is a sample pom of a project using "internal-repository-group"

<repositories>
    <repository>
        <id>internal-repository-group</id>
        <name>repo-name</name>
        <url>http://project.com/yourrepourl/</url>
        <layout>default</layout>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
        </releases>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
        </snapshots>
    </repository>
</repositories>
变身佩奇 2024-08-31 05:32:22

基本上,Maven 告诉您的只是项目中的某些依赖项在中央 Maven 存储库中不可用。默认情况是查看本地 .m2 文件夹(本地存储库),然后查看 POM 中任何已配置的存储库,然后查看中央 Maven 存储库。查看 Maven 参考的存储库部分

问题在于,签入的项目没有以可以找到所有依赖项并且可以从头开始构建项目的方式配置 POM。

Basically, all Maven is telling you is that certain dependencies in your project are not available in the central maven repository. The default is to look in your local .m2 folder (local repository), and then any configured repositories in your POM, and then the central maven repository. Look at the repositories section of the Maven reference.

The problem is that the project that was checked in didn't configure the POM in such a way that all the dependencies could be found and the project could be built from scratch.

爱人如己 2024-08-31 05:32:22

从你的maven文件夹中更改settings.xml,例如
C:\Program Files\apache-maven-3.6.3\conf
检查上面的路径..

change the settings.xml from your maven folder e.g
C:\Program Files\apache-maven-3.6.3\conf
check above path..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文