This message was deleted.
# community-support
s
This message was deleted.
c
Using this pattern:
Copy code
public fun <T> ProviderFactory.conditionalListOf(predicate: Provider<Boolean>, vararg elements: T): Provider<List<T>> {
    return predicate.orElse(false).map {
        if (it) {
            elements.toList()
        } else {
            emptyList()
        }
    }
}
Copy code
named(BUILD_TASK_NAME) {
            dependsOn(providers.conditionalListOf(providers.ciBuild().negate(), spotlessApply))
        }
is it
dependsOn
you are after? If not this may be applicable:
Copy code
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.
c
Okay I'll give those a go later.
Having not tried it yet I am trying to understand how those would tell the task not to do anything. Or perhaps tell the task that is already up to date. Basically I just need the exec command not to run if in CI
If it is in CI it should basically be up to date. as that command has run before commit
c
ok, so not dependsOn but onlyIf.
Copy code
public fun Task.onlyIf(spec: Provider<Boolean>) {
    onlyIf { spec.getOrElse(false) }
}
Copy code
onlyIf {
                when {
                    isCIBuild() -> when {
                        isSnapshotVersion() -> repository.isSnapshotRepo()
                        else -> repository.isReleaseRepo()
                    }

                    else -> repository.isLocalRepo()
                }
            }
c
Gotcha
c
pulled from my code; you could use something like
onlyIf { providers.environmentVariable("CI") }
c
With the only if go in my generate Java task? Like only if depends on?
Only if depends on generate graphql
c
just on the tasks you wish to be conditional. No need to modify the dependencies (doable but trickier and not necessary).
sounds like that would be your generate java task and graphql task.
c
I'll give it a go when I get back home
👍 1