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

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

    >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 -e -U -Dmaven.test.skip=true

-e详细异常 -U强制更新 -DskipTests不执行测试用例,但编译测试用例类,在目标/测试类下生成相应的类文件。 -Dmaven.test。Skip =true,不执行测试用例或编译测试用例类。使用maven。测试。Skip不仅跳过运行单元测试,还跳过编译测试代码。

一个小建议。如果使用IntelliJ Idea编译器,建议清理缓存

其他回答

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

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

mvn clean install -U

-U表示强制更新快照依赖项。

如果之前从未成功下载过发布依赖项,则将以这种方式更新。裁判:https://stackoverflow.com/a/29020990/32453

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

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

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

如果你不确定本地存储库中有什么,我建议使用以下选项启动构建:

-Dmaven.repo.local=localrepo

这样你就能确保在一个洁净的环境中建造。

如果你的本地存储库在某种程度上为发布jar而不是快照(-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