如何让 Maven 使用正确的存储库?
我刚刚检查了一些项目并需要构建它们,但是我很久以前就安装了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
所有项目都有默认的https://repo1.maven.org/ 声明为
(和
)默认情况下。这个存储库称为中央存储库,它像其他默认设置一样从“Super POM”继承(所有项目都继承自Super POM)。所以 POM 实际上是 Super POM、任何父 POM 和当前 POM 的组合。这种组合称为“有效的 POM”,可以使用 Maven 帮助插件的 effective-pom
目标进行打印(对于调试很有用)。事实上,如果你运行:
你至少会看到以下内容:
Maven 将尝试在声明的所有存储库中查找依赖项,包括在 central 存储库中正如我们所见,默认情况下。但是,根据您显示的跟踪,您只定义了 一个 存储库(中央存储库),否则 maven 会打印如下内容:
所以,基本上,maven 无法找到 url .project:project:pom:xx 因为它在central中不可用。
但是,如果不知道您签出了哪个项目(它可能有具体的说明)或缺少哪个依赖项(它可能可以在另一个存储库中找到),就不可能为您提供进一步的帮助。
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 theeffective-pom
goal of the Maven Help plugin (useful for debugging).And indeed, if you run:
You'll see at least the following:
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:
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.
默认情况下,Maven 将始终在官方 Maven 存储库中查找,即 http://repo1.maven.org。
当 Maven 尝试构建项目时,它将在您的本地存储库中查找(默认情况下
~/.m2/repository
但您可以通过更改
来配置它~/.m2/settings.xml
中的值)来查找pom.xml
中定义的任何依赖项、插件或报告。如果在本地存储库中找不到足够的工件,它将在所有配置的外部存储库中查找,从默认存储库 http: //repo1.maven.org。您可以通过在
settings.xml
文件中设置镜像来配置 Maven 以避免使用此默认存储库:这样,就不用联系
http://repo1.maven.org
, Maven 将联系您的企业存储库(本例中为http://the/server
)。如果您想添加另一个存储库,可以在 settings.xml 文件中定义一个新存储库:
您可以看到完整的
settings.xml
模型 此处。关于
clean
过程,您可以要求Maven离线运行它。在这种情况下,Maven 将不会尝试访问任何外部存储库: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 yourpom.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: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:
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:tl;dr
所有 Maven POM 都继承自基础 超级 POM< /strong>。
下面的代码片段是 Maven 3.5.4 的 Super POM 的一部分。
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.
我认为您在这里错过的是:
https://maven.apache.org/settings。 html#服务器
这是使用自定义存储库的首选方式。因此,可能发生的情况是该存储库的 url 位于构建服务器的 settings.xml 中。
一旦您掌握了 url 和凭据,您就可以将它们放入您的计算机中:
~/.m2/settings.xml
,如下所示:编辑:
然后您需要将此存储库引用到项目 POM 中。 ID internal-repository-group 可以在每个项目中使用。您可以在设置 xml 中使用不同的 ID 设置多个存储库和凭据设置。
这种方法的优点是可以共享项目而无需担心凭据,并且不必在每个项目中提及凭据。
以下是使用“internal-repository-group”的项目示例 pom
I think what you have missed here is this:
https://maven.apache.org/settings.html#Servers
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: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"
基本上,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.
从你的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..