引言
近日一直忙著做持續集成,處于安全性考慮,需要在離線環境運行,專案依托Jenkins做Java/Python/Vue等工程的鏡像構建,其中Java工程基本基于Maven,在外網條件下通過IDEA或者mvn命令均可正常打包,原本思路是將本地的repo全量拷貝到服務器,再執行同樣的mvn命令,但實際出發jenkins構建任務時,經常build失敗,哪怕在maven的setting.xml中硬性設定<offline>true</offline>,依舊不起作用,

問題原因探索
maven在執行構建程序中,會按照localRepo->privateRepo->mirrorRepo->centralRepo依次去解決包缺失問題,并最終下載到localRepo,因為是全量拷貝windows的localRepo,里邊存在了大量的_remote.repositories檔案,此檔案直接影響了部分jar的同步問題,導致哪怕localRepo明明已經有了jar包,還是固執地去上級倉庫拉包,然而我們沒有環境配置nexus和mirror,故只能向centralRepo找尋jar包,導致build失敗,
行之有效的解決辦法
1.在不設定nexus的情況下,直接偽造一個mirror源,指向服務器localRepo,需要在maven的setting.xml檔案中,新增一個mirror,格式如下,
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>central</id>
<mirrorOf>*</mirrorOf>
<name>central</name>
<url>file:///data/maven_repo/Mvn363</url>
</mirror>
</mirrors>
2.洗掉localRepo下所有的_remote.repositories檔案
# 查詢所有的_remote.repositories
find . -name _remote.repositories
# 洗掉當前目錄下所有的_remote.repositories
find . -name _remote.repositories | xargs -I {} rm -fr {}
3.再次觸發jenkins構建任務,無誤,

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/542582.html
標籤:其他
上一篇:SSL 證書基本概念掃盲
