错误描述
[ERROR] Failed to execute goal on project ******: Could not resolve dependencies for project com.******😗**:jar:.: Failed to collect dependencies at org.springframework.integration:spring-integration-ip:jar:4.3.18.RELEASE: Failed to read artifact descriptor for org.springframework.integration:spring-integration-ip:jar:4.3.18.RELEASE: Could not transfer artifact org.springframework.integration:spring-integration-ip:pom:4.3.18.RELEASE from/to central (https://repo.maven.apache.org/maven2): connect timed out -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
问题分析
根据问题描述,可知是由于无法解决项目依赖问题导致。涉及的依赖包是org.springframework.integration:
- 在org.springframework.integration上收集依赖项失败
- 未能读取org.springframework.integration的构件描述符
- 无法从Maven中心(https://repo.maven.apache.org/maven2)传递组件spring-integration-ip:pom:4.3.18.RELEASE: 连接超时
初步分析,可能是本地的repo有问题。
解决方案
首先介绍几个mvn命令:
- mvn -U clean install: -U,–update-snapshots Forces a check for updated releases and snapshots on remote,即通过-U命令强制从远程仓库重新下载相关的dependency
- mvn clean install -DskipTests:与上边同理,-DskipTests,即跳过测试代码
- mvn package:Maven打包编译
通过命令行控制台,进入到project的目录中,即含有POM.xml的文件夹,执行任一上述命令,均能看到如下结果:
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 46.380 s
[INFO] Finished at: 2020-05-12T17:54:24+08:00
[INFO] ------------------------------------------------------------------------
即编译成功。
注意:此时需要能够在命令行中执行Maven命令,即Maven注册在了环境变量里。
或者,我们使用Eclipse进行打包编译。这里,我们使用的Maven配置文件位置是.m2/setting.xml,使用的是镜像地址是
https://maven.aliyun.com/repository/central,配置如下:
<mirrors>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>central</name>
<url>https://maven.aliyun.com/repository/central</url>
</mirror>
</mirrors>
然后执行update project,Run maven build,执行编译过程。需要注意的是,如果网络环境差,还是会导致这样的错误。如果仍然出现错误,则将对应的jar包下载后导入到Eclipse中。
最后,分享一个Aliyun的Maven仓库:https://maven.aliyun.com/mvn/view