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

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

    >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

它仍然显示相同的错误,然后我关闭项目,再次重新打开它。最后工作。

其他回答

以前版本的maven在mvn clean install中使用-U时不强制检查丢失的版本,只检查快照,但新版本支持这一点。

对于那些还在为以前的版本而挣扎的人来说,下面的内容可能会有所帮助

在Windows上:

cd %userprofile%\.m2\repository
for /r %i in (*.lastUpdated) do del %i

在Linux上:

find ~/.m2  -name "*.lastUpdated" -exec grep -q "Could not transfer" {} \; -print -exec rm {} \;

每当maven由于任何原因(连通性/不存在等)无法下载依赖项时,它将添加“。错误=不能转移工件"在依赖项名称。lastUpdate文件在$home/下的相应文件夹。m2目录。删除这些文件将迫使maven再次尝试获取依赖项。

我们可以使用以下命令强制获取最新的发布和快照存储库更新:

mvn --update-snapshots clean install

我在另一个上下文中得到了错误。 所以我的解决方案可能对其他遇到这个问题的人有用:

存在的问题: 我已将本地存储库复制到另一台计算机,该计算机没有连接到特殊存储库。 因此maven尝试对照无效的存储库检查工件。

我的解决方案: 删除_maven。库文件。

我使用了IntelliJ IDE,我有一个类似的问题,为了解决这个问题,我在Maven选项卡中单击“为所有项目生成源代码和更新文件夹”。

我有同样的错误,运行mvn install -U,然后运行mvn install为我工作。