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

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

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


当前回答

如果你正在使用eclipse IDE,那么:

选择项目。 按alt+F5,更新Maven项目窗口将弹出。 检查-强制更新快照/发布,单击“确定”。

如果使用Intellij IDE

进入settings/Maven 总是更新快照

其他回答

这是Maven最烦人的事情之一。对我来说,会发生以下情况:如果我添加了一个依赖项,请求更多的依赖项,但是连接很慢,它会在下载和超时时停止。在计时时,所有尚未获取的依赖项都在.m2缓存中用占位符标记,Maven不会(永远不会)拾取它,除非我通过删除它从缓存中删除占位符条目(如前所述)。

所以就我所知,Maven或者更准确的说是Eclipse Maven插件在这方面有一个bug。应该有人报告此事。

以防有人只想更新项目的快照依赖项而不想安装工件:

mvn dependency:resolve -U

不要忘记在IDE中重新导入依赖项。在IDEA中,您需要右键单击pom文件,并选择Maven ->重新导入

我试了这里所有的答案,但似乎都不管用。重启我的电脑,然后运行mvn clean install -U。这解决了我的问题。

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

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

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

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