协慌网

登录 贡献 社区

如何强制 Maven 更新?

我将已经工作的项目导入另一台计算机,并且该项目开始下载依赖项。

显然我的互联网连接崩溃了,现在我得到了以下信息:

>Build errors for comics; org.apache.maven.lifecycle.LifecycleExecutionException:
    Failed to execute goal on project comicsTest: Could not resolve dependencies for project comicsTest:comicsTest:war:0.0.1-SNAPSHOT:
    The following artifacts could not be resolved:
    org.springframework:spring-context:jar:3.0.5.RELEASE,
    org.hibernate:hibernate-entitymanager:jar:3.6.0.Final,
    org.hibernate:hibernate-core:jar:3.6.0.Final,
    org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final,
    org.aspectj:aspectjweaver:jar:1.6.8,
    commons-lang:commons-lang:jar:2.5,

    >mysql:mysql-connector-java:jar:5.1.13: Failure to transfer org.springframework:spring-context:jar:3.0.5.RELEASE from http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced.

    >Original error: Could not transfer artifact org.springframework:spring-context:jar:3.0.5.RELEASE from central (http://repo1.maven.org/maven2): No response received after 60000

如何强制 Maven 更新?

答案

mvn clean install -U

-U表示强制更新快照依赖项。发布依赖项无法通过这种方式进行更新。

如果您的本地存储库以某种方式为释放罐而不是快照( -U--update-snapshots仅更新快照)进行了存储,则可以使用以下方法清除本地存储库:

mvn dependency:purge-local-repository

然后,您可能想要再次清洁并安装:

mvn dependency:purge-local-repository clean install

有关更多信息,请访问https://maven.apache.org/plugins/maven-dependency-plugin/examples/purging-local-repository.html

-U似乎强制更新所有依赖项。

-U来更新单个依赖项,则可以将其从本地存储库中删除,然后进行构建。

以下示例用于更新slf4j-api 1.7.1-SNAPSHOT

rm -rf ~/.m2/repository/org/slf4j/slf4j-api/1.7.1-SNAPSHOT
mvn compile