我先說下我的打包步驟
一、復現
我的應用中有兩個模塊:client和common
其中client依賴common
打包步驟
先打包common,build success
再打包client,此時出錯!錯誤信息如下
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< org.example:client >-------------------------
[INFO] Building client 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.309 s
[INFO] Finished at: 2020-06-17T16:58:00+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project client: Could not resolve dependencies for project org.example:client:jar:1.0-SNAPSHOT: Failed to collect dependencies at org.example:common:jar:1.0-SNAPSHOT: Failed to read artifact descriptor for org.example:common:jar:1.0-SNAPSHOT: Could not find artifact org.example:project-test:pom:1.0-SNAPSHOT -> [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
二、排查
上面錯誤信息中,有兩行提示,我們摘出來
## 查看完整錯誤棧信息,可以添加-e 參數
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
## 查看完整的debug日誌,可以添加-X 參數
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
1. 使用-e參數重新install
我們進入到client文件夾下,使用-e參數重新打包試試,看看它的異常棧信息
cd client
mvn clean install -e
2. 查看異常棧
異常棧很長查看最後一個即可,錯誤棧截圖如下
清晰明瞭,打包異常的原因,就是因爲沒有找到org.example:project-test:pom:1.0-SNAPSHOT這個包!
三、解決
上面異常棧中org.example:project-test:pom:1.0-SNAPSHOT這個包,也就是子模塊的父項目,即項目本身project-test。打包一下這個父項目,就能解決了。
結論
client打包時依賴common,而common依賴父工程project-test。
所以client先去本地查找project-test這個包;沒找到就去私服中找,肯定還沒找到;進而去中央倉庫查找,還是沒找到,就報錯了!
四、授之以漁
- 遇到打包錯誤的情況不要慌,直接加-X或者-e參數重新打包,看看錯誤日誌是什麼,一般都會顯示很清楚的。
-X 參數:顯示打包過程中的debug日誌
-e 參數:顯示完成錯誤棧信息 - 仔細看錯誤信息
我們把最初的報錯信息再摘出來一段:
[ERROR] Failed to execute goal on project client: Could not resolve dependencies for project org.example:client:jar:1.0-SNAPSHOT: Failed to collect dependencies at org.example:common:jar:1.0-SNAPSHOT: Failed to read artifact descriptor for org.example:common:jar:1.0-SNAPSHOT: Could not find artifact org.example:project-test:pom:1.0-SNAPSHOT -> [Help 1]
直接看最後一個錯誤,也能很清晰的看到提示缺少project-test:pom:1.0-SNAPSHOT這個包。