Slackbot
10/05/2022, 8:09 PMChris Lee
10/05/2022, 8:21 PMpublic fun <T> ProviderFactory.conditionalListOf(predicate: Provider<Boolean>, vararg elements: T): Provider<List<T>> {
return predicate.orElse(false).map {
if (it) {
elements.toList()
} else {
emptyList()
}
}
}
named(BUILD_TASK_NAME) {
dependsOn(providers.conditionalListOf(providers.ciBuild().negate(), spotlessApply))
}
Chris Lee
10/05/2022, 8:22 PMdependsOn
you are after? If not this may be applicable:
public inline fun <reified S> Provider<S>.filter(crossinline predicate: (S) -> Boolean): Provider<S> {
return flatMap {
if (predicate(it)) {
Providers.of(it)
} else {
Providers.notDefined()
}
}
}
…returns an empty provider is the condition is not met.Caleb Cushing
10/05/2022, 9:03 PMCaleb Cushing
10/05/2022, 9:06 PMCaleb Cushing
10/05/2022, 9:06 PMChris Lee
10/05/2022, 9:07 PMpublic fun Task.onlyIf(spec: Provider<Boolean>) {
onlyIf { spec.getOrElse(false) }
}
onlyIf {
when {
isCIBuild() -> when {
isSnapshotVersion() -> repository.isSnapshotRepo()
else -> repository.isReleaseRepo()
}
else -> repository.isLocalRepo()
}
}
Caleb Cushing
10/05/2022, 9:08 PMChris Lee
10/05/2022, 9:08 PMonlyIf { providers.environmentVariable("CI") }
Caleb Cushing
10/05/2022, 9:10 PMCaleb Cushing
10/05/2022, 9:11 PMChris Lee
10/05/2022, 9:11 PMChris Lee
10/05/2022, 9:12 PMCaleb Cushing
10/05/2022, 9:18 PM