實際專案常需從多個來源解析依賴,常見場景包括:
Ivy 透過 Chain Resolver(解析器鏈) 組合多個解析器,按順序查找,滿足上述需求。
專案 chained-resolvers 依賴兩個模組:
commons-lang:2.0(第三方,來自 Maven Central)org.apache#test:1.0(內部測試庫,來自本地檔案系統)<ivysettings>
<settings defaultResolver="chain-example"/>
<resolvers>
<chain name="chain-example">
<filesystem name="libraries">
<artifact pattern="${ivy.settings.dir}/repository/[artifact]-[revision].[ext]"/>
</filesystem>
<ibiblio name="ibiblio" m2compatible="true"/>
</chain>
</resolvers>
</ivysettings>
libraries(檔案系統)優先查找本地 repository/ 目錄。ibiblio(Maven Central)。進入 chained-resolvers/chainedresolvers-project 執行 ant:
found [ commons-lang | commons-lang | 2.0 ] in ibiblio
found [ org.apache | test | 1.0 ] in libraries
| default | 2 | 2 | 0 | 0 || 2 | 2 |
test 從本地 libraries 解析器獲取。commons-lang 從 ibiblio 獲取。false 可聚合多來源結果(罕用)。dual="false"(預設)時,找到 metadata 的解析器將被綁定用於該模組的 artifact 下載。解析器鏈是 Ivy 靈活儲存庫路由的基石。透過簡單的宣告式配置,即可實現企業級的多來源依賴解析策略,完美支援本地開發、團隊共享、公共獲取的分層工作流。