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

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

    >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更新?


当前回答

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

如果你想在没有clean或-U的情况下更新单个依赖,你可以从本地repo中删除它,然后构建。

下面的例子用于更新slf4j-api 1.7.1-SNAPSHOT:

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

其他回答

使用mvn clean install -U run as maven test之后,使用maven-update project更新你的项目 这对我来说是可行的

What maven does is, it downloads all your project's dependencies into your local repo (.m2 folder). Because of the internet causing issues with your local repo, you project is facing problems. I am not sure if this will surely help you or not but you can try deleting all the files within the repository folder inside the .m2 folder. Since there would be nothing in the local repo, maven would be forced to download the dependencies again, thus forcing an update. Generally, the .m2 folder is located at c:users:[username]:.m2

您可以从Eclipse IDE中有效地完成这些工作。当然,如果你在用的话。

Project_Name->Maven->Update Project Configuration->Force Update of Snapshots/Releases

-U用于强制更新maven Repo。 使用

mvn -U clean install

重要的是,使用-U和不使用-U运行mvn的主要区别是-U将用远程SNAPSHOT jar覆盖本地SNAPSHOT jar。

如果你的proj中有其他模块生成jar,则从本地mvn安装创建本地快照jar。