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)

新增一個元件選擇規則,該規則將應用於所有已解析的元件。每個規則將接收一個 ComponentSelection 物件作為引數。

all(ruleSource)

新增一個由規則來源支援的元件選擇規則,該規則將應用於所有已解析的元件。ruleSource 提供規則作為精確地一個使用 Mutate 註解的規則方法。此規則方法

all(selectionAction)

新增一個簡單的元件選擇規則,該規則將應用於所有已解析的元件。每個規則將接收一個 ComponentSelection 物件作為引數。

withModule(id, closure)

新增一個元件選擇規則,該規則將應用於指定的模組。每個規則將接收一個 ComponentSelection 物件作為引數。

withModule(id, ruleSource)

新增一個由規則來源支援的元件選擇規則,該規則將應用於指定的模組。ruleSource 提供規則作為精確地一個使用 Mutate 註解的規則方法。此規則方法

withModule(id, selectionAction)

新增一個元件選擇規則,該規則將應用於指定的模組。每個規則將接收一個 ComponentSelection 物件作為引數。

腳本區塊

無腳本區塊

方法詳情

新增一個元件選擇規則,該規則將應用於所有已解析的元件。每個規則將接收一個 ComponentSelection 物件作為引數。

新增一個由規則來源支援的元件選擇規則,該規則將應用於所有已解析的元件。ruleSource 提供規則作為精確地一個使用 Mutate 註解的規則方法。此規則方法

ComponentSelectionRules all(Action<? super ComponentSelection> selectionAction)

新增一個簡單的元件選擇規則,該規則將應用於所有已解析的元件。每個規則將接收一個 ComponentSelection 物件作為引數。

ComponentSelectionRules withModule(Object id, Closure<?> closure)

新增一個元件選擇規則,該規則將應用於指定的模組。每個規則將接收一個 ComponentSelection 物件作為引數。

ComponentSelectionRules withModule(Object id, Object ruleSource)

新增一個由規則來源支援的元件選擇規則,該規則將應用於指定的模組。ruleSource 提供規則作為精確地一個使用 Mutate 註解的規則方法。此規則方法

ComponentSelectionRules withModule(Object id, Action<? super ComponentSelection> selectionAction)

新增一個元件選擇規則,該規則將應用於指定的模組。每個規則將接收一個 ComponentSelection 物件作為引數。