API 文件 | ComponentSelectionRules |
---|
代表元件選擇規則的容器。規則可以作為組態的 resolutionStrategy 的一部分應用,並且可以通過規則顯式接受或拒絕個別元件。既未接受也未拒絕的元件將受預設版本匹配策略的約束。
configurations { conf { resolutionStrategy { componentSelection { all { ComponentSelection selection -> if (selection.candidate.module == 'someModule' && selection.candidate.version == '1.1') { selection.reject("bad version '1.1' for 'someModule'") } } all { ComponentSelection selection -> if (selection.candidate.module == 'someModule' && selection.getDescriptor(IvyModuleDescriptor)?.branch == 'testing') { if (selection.metadata == null || selection.metadata.status != 'milestone') { selection.reject("only use milestones for someModule:testing") } } } withModule("org.sample:api") { ComponentSelection selection -> if (selection.candidate.version == "1.1") { selection.reject("known bad version") } } } } } }
方法 | 描述 |
all(closure) | 新增一個元件選擇規則,該規則將應用於所有已解析的元件。每個規則將接收一個 |
all(ruleSource) | 新增一個由規則來源支援的元件選擇規則,該規則將應用於所有已解析的元件。ruleSource 提供規則作為精確地一個使用 |
all(selectionAction) | 新增一個簡單的元件選擇規則,該規則將應用於所有已解析的元件。每個規則將接收一個 |
withModule(id, closure) | 新增一個元件選擇規則,該規則將應用於指定的模組。每個規則將接收一個 |
withModule(id, ruleSource) | 新增一個由規則來源支援的元件選擇規則,該規則將應用於指定的模組。ruleSource 提供規則作為精確地一個使用 |
withModule(id, selectionAction) | 新增一個元件選擇規則,該規則將應用於指定的模組。每個規則將接收一個 |
ComponentSelectionRules
all
(Closure
<?>
closure)
Closure
<?>新增一個元件選擇規則,該規則將應用於所有已解析的元件。每個規則將接收一個 ComponentSelection
物件作為引數。
ComponentSelectionRules
all
(Object
ruleSource)
新增一個由規則來源支援的元件選擇規則,該規則將應用於所有已解析的元件。ruleSource 提供規則作為精確地一個使用 Mutate
註解的規則方法。此規則方法
- 必須返回 void。
- 必須將
ComponentSelection
作為其參數。
ComponentSelectionRules
all
(Action
<? super ComponentSelection
>
selectionAction)
Action
<? super ComponentSelection
>新增一個簡單的元件選擇規則,該規則將應用於所有已解析的元件。每個規則將接收一個 ComponentSelection
物件作為引數。
ComponentSelectionRules
withModule
(Object
id, Closure
<?>
closure)
Closure
<?>新增一個元件選擇規則,該規則將應用於指定的模組。每個規則將接收一個 ComponentSelection
物件作為引數。
ComponentSelectionRules
withModule
(Object
id, Object
ruleSource)
新增一個由規則來源支援的元件選擇規則,該規則將應用於指定的模組。ruleSource 提供規則作為精確地一個使用 Mutate
註解的規則方法。此規則方法
- 必須返回 void。
- 必須將
ComponentSelection
作為其參數。
ComponentSelectionRules
withModule
(Object
id, Action
<? super ComponentSelection
>
selectionAction)
Action
<? super ComponentSelection
>新增一個元件選擇規則,該規則將應用於指定的模組。每個規則將接收一個 ComponentSelection
物件作為引數。