This is the way I've solved this for my own use case. The following allows exclusion rules to be added that filter candidates during dependency resolution.
Candidates matching regular expression exclusion rules are rejected.
This is Kotlin DSL, but would probably work just as well if converted to Groovy.
configurations.all {
resolutionStrategy
.componentSelection
.all(object : Action<ComponentSelection> {
@Mutate
override fun execute(selection : ComponentSelection) {
// Add exclusion rules here
excludeSelectionByRegex(selection, "org\\.jetbrains.*", ".*", ".*-(eap|M).*")
excludeSelectionByRegex(selection, "org\\.my-group.*", "my-module", ".*-beta")
}
})
}
fun excludeSelectionByRegex(selection: ComponentSelection, groupRegex: String, moduleRegex: String, versionRegex: String) {
if (groupRegex.toRegex().matches(selection.candidate.group) &&
moduleRegex.toRegex().matches(selection.candidate.module) &&
versionRegex.toRegex().matches(selection.candidate.version)
) {
selection.reject("Matched exclusion rule")
}
}