Java 为什么Maven每次都下载maven-metadata.xml?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16421454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is Maven downloading the maven-metadata.xml every time?
提问by quarks
Below is the error I usually get when my internet connection is flanky when trying to build a web application with maven.
以下是我在尝试使用 maven 构建 Web 应用程序时,当我的互联网连接出现问题时通常会遇到的错误。
My question is that, why does maven always have to download every time when the same app has been built earlier.
我的问题是,为什么每次构建相同的应用程序时,maven 总是必须下载。
What could be wrong in my configuration that makes maven to download every time?
我的配置中可能有什么问题导致 maven 每次都下载?
Below is an error I get when I try to build offline:
以下是我尝试离线构建时遇到的错误:
[INFO] ------------------------------------------------------------------------
[INFO] Building mywebapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://raw.github.com/pagecrumb/mungo/mvn-repo/com/pagecrumb/mungo/0.0.1-SNAPSHOT/maven-metadata.xml
[WARNING] Could not transfer metadata com.mywebapp:mungo:0.0.1-SNAPSHOT/maven-metadata.xml
from/to mungo-mvn-repo (https://raw.github.com/pagecrumb/mungo/mvn-repo/): raw.github.com
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-cli) @ mywebapp ---
[INFO] Packaging webapp
[INFO] Assembling webapp [mywebapp] in [D:\workspace\web\target\mywebapp-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [D:\workspace\web\src\main\webapp]
[INFO] Webapp assembled in [1237 msecs]
[INFO] Building war: D:\workspace\web\target\mywebapp-1.0-SNAPSHOT.war
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored
(webxml attribute is missing from war task,
or ignoreWebxml attribute is specified as 'true')
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building com.mywebapp [com.mywebapp] 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-release-plugin/2.1/maven-release-plugin-2.1.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-release-plugin:2.1: Plugin org.apache.maven.plugins:maven-release-plugin:2.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-release-plugin:jar:2.1
Downloading: http://download.java.net/maven/2/org/apache/maven/plugins/maven-metadata.xml
Downloading: http://download.java.net/maven/2/org/codehaus/mojo/maven-metadata.xml
397/397 B
Downloaded: http://download.java.net/maven/2/org/codehaus/mojo/maven-metadata.xml (397 B at 0.0 KB/sec)
[WARNING] Failure to transfer org.apache.maven.plugins:maven-war-plugin/maven-metadata.xml from http://download.java.net/maven/2 was cached in the local repository, resolution will not be reattempted until the update interval of maven2-repository.dev.java.net has elapsed or updates are forced. Original error: Could not transfer metadata org.apache.maven.plugins:maven-war-plugin/maven-metadata.xml from/to maven2-repository.dev.java.net (http://download.java.net/maven/2): download.java.net
[INFO]
[INFO] --- maven-war-plugin:2.3:war (default-cli) @ mywebapp-build ---
[INFO] Packaging webapp
[INFO] Assembling webapp [mywebapp-build] in [D:\workspace\target\mywebapp-build-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Webapp assembled in [15 msecs]
[INFO] Building war: D:\workspace\target\mywebapp-build-0.0.1-SNAPSHOT.war
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] mywebapp ..................................... SUCCESS [27.999s]
[INFO] com.mywebapp [com.mywebapp] ..................... FAILURE [1:00.406s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:41.409s
[INFO] Finished at: Tue May 07 22:13:38 SGT 2013
[INFO] Final Memory: 11M/28M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.3:war
(default-cli) on project mywebapp-build: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
采纳答案by user944849
Look in your settings.xml
(or, possibly your project's parent or corporate parent POM) for the <repositories>
element. It will look something like the below.
在您的settings.xml
(或者,可能是您项目的父级或公司父级 POM)中查找该<repositories>
元素。它看起来像下面这样。
<repositories>
<repository>
<id>central</id>
<url>http://gotoNexus</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</releases>
</repository>
</repositories>
Note the <updatePolicy>
element. The example tells Maven to contact the remote repo (Nexus in my case, Maven Central if you're not using your own remote repo) any time Maven needs to retrieve a snapshot artifact during a build, checking to see if there's a newer copy. The metadata is required for this. If there is a newer copy Maven downloads it to your local repo.
注意<updatePolicy>
元素。该示例告诉 Maven 在构建期间任何时候 Maven 需要检索快照工件时联系远程存储库(在我的情况下为 Nexus,如果您不使用自己的远程存储库,则为 Maven Central),检查是否有更新的副本。为此需要元数据。如果有更新的副本,Maven 会将其下载到您的本地存储库。
In the example, for releases, the policy is daily
so it will check during your first build of the day. never
is also a valid option, as described in Maven settings docs.
在示例中,对于发布,策略是daily
在您当天的第一次构建期间进行检查。 never
也是一个有效的选项,如Maven settings docs 中所述。
Plugins are resolved separately. You may have repositories configured for those as well, with different update policies if desired.
插件单独解决。您也可以为这些配置存储库,如果需要,可以使用不同的更新策略。
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://gotoNexus</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
Someone else mentioned the -o
option. If you use that, Maven runs in "offline" mode. It knows it has a local repo only, and it won't contact the remote repo to refresh the artifacts no matter what update policies you use.
其他人提到了这个-o
选项。如果您使用它,Maven 将在“离线”模式下运行。它知道它只有一个本地存储库,并且无论您使用什么更新策略,它都不会联系远程存储库来刷新工件。
回答by Puce
I haven't studied yet, when Maven does which look-up, but to get stable and reproducible builds, I strongly recommend not to access Maven Respositories directly but to use a Maven Repository Manager such as Nexus.
我还没有研究过,当 Maven 进行哪个查找时,但为了获得稳定和可重复的构建,我强烈建议不要直接访问 Maven Respositories,而是使用 Maven Repository Manager,例如 Nexus。
Here is the tutorial how to set up your settings file:
这是如何设置设置文件的教程:
http://books.sonatype.com/nexus-book/reference/maven-sect-single-group.html
http://books.sonatype.com/nexus-book/reference/maven-sect-single-group.html
回答by Gab
I suppose because you didn't specify plugin version so it triggers the download of associated metadata in order to get the last one.
我想是因为您没有指定插件版本,所以它会触发相关元数据的下载以获得最后一个。
Otherwise did you try to force local repo usage using -o ?
否则,您是否尝试使用 -o 强制使用本地存储库?
回答by jfc
It is possibly to use the flag -o,--offline "Work offline"
to prevent that.
可能会使用标志-o,--offline "Work offline"
来防止这种情况。
Like this:
像这样:
maven compile -o
maven compile -o
回答by Tomask
Maven does this because your dependency is in a SNAPSHOT version and maven has no way to detect any changes made to that snapshot version in the repository. Release your artifact and change the version in pom.xml to that version and maven will no longer fetch the metadata file.
Maven 这样做是因为您的依赖项位于 SNAPSHOT 版本中,而 Maven 无法检测对存储库中该快照版本所做的任何更改。释放您的工件并将 pom.xml 中的版本更改为该版本,maven 将不再获取元数据文件。