为什么Maven每次下载maven-metadata.xml?

下面是当我尝试使用maven构build一个web应用程序时,我的互联网连接出现故障时,我通常会遇到的错误。

我的问题是,为什么每次在同一个应用程序build立之前,maven总是需要下载。

什么可能是错误的,我的configuration,使Maven每次下载?

以下是我尝试离线构build时遇到的错误:

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

查看您的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> 

请注意<updatePolicy>元素。 这个例子告诉Maven在任何时候联系远程仓库(在我的例子中是Nexus,如果你没有使用自己的远程仓库,Maven中心),Maven需要在构build过程中检索快照构件,检查是否有新的副本。 元数据是必需的。 如果有更新的副本,Maven会将其下载到您当地的回购站点。

在示例中,对于发布,策略是daily因此它将在您第一次构build当天的过程中进行检查。 never是一个有效的select,如Maven设置文档中所述 。

插件分开解决。 您也可以为这些configuration存储库,如果需要,可以使用不同的更新策略。

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

其他人提到了-o选项。 如果使用它,Maven将以“脱机”模式运行。 它知道它只有一个本地repo,不会联系远程repo刷新工件,不pipe你使用什么更新策略。

我想,因为你没有指定插件版本,所以它触发下载相关的元数据,以获得最后一个。

否则,你尝试使用-o强制本地回购使用?

可能使用标志-o,--offline "Work offline"来防止这种情况发生。

喜欢这个:

maven compile -o

我还没研究过,当Maven做查找时,为了获得稳定和可重复的构build,我强烈build议不要直接访问Maven Respositories,而是使用Maven Repository Manager(如Nexus)。

这里是教程如何设置您的设置文件:

http://books.sonatype.com/nexus-book/reference/maven-sect-single-group.html

http://maven.apache.org/repository-management.html