This message was deleted.
# community-support
s
This message was deleted.
2
c
Add the dependency to the task unconditionally; on the depenendency task add an onlyIf block to conditionally execute.
🙌 2
a
That makes sense, thanks!
v
Actually, using
dependsOn
is almost never the right thing to do, unless "dependent" is a lifecycle task. Instead your should wire task outputs to task inputs and get the necessary task dependencies implicitly automatically.
a
I see, and in this case that would mean we will create a task that stores the flag in an output file? Will have to try this out for defining conditional dependency
Copy code
tasks.register("isCi") {
    doLast {
        project.layout.buildDirectory.file("IsCi")
            .also { outputFile ->
                val isCi = isCi(project)
                outputFile.get().asFile.writeText(isCi)
                task.outputs.file(outputFile)
            }    
    }
}
v
I don't think you got me right. Calculating an
isCI
and doing conditional logic depending on it is fine. If your are concerned about doing the calculation multiple times because it is costly, just user a local variable in the build script if once per script is seldom enough, or use a build service if not. What I meant is, that an explicit
dependsOn
is practically always wrong unless you have a lifecycle task on the left-hand side.
👆 1