【Q&A】Maven 打包錯誤:Failed to collect dependencies at org.springframework.integration

Failed to collect dependencies at org.springframework.integration

錯誤描述

[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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章