With @Cisco's comment I started to dig more into the lifecycle of Gradle. After digging in a bit, I found afterEvaluate - Adds a closure to call immediately after this project is evaluated.
This is too late in the lifecycle to modify the executing tasks.
What I wanted to do was conditionally execute a tasks provided by a plugin after the 'build' task had completed. In case anyone else is interested, here is the process.
Step 1: Update the task I want to conditionally run to be conditional.
tasks.getByName("artifactoryPublish").onlyIf {
properties["isPublishingEnabled"].toString().toBooleanStrict()
}
This will check the isPublishingEnabled property, and run the artifactoryPublish
task only if the property is true.
Step 2: Attach it to the build
.
tasks.getByName("build").finalizedBy("artifactoryPublish")
This directs tells gradle to run artifactoryPublish
once build
completes.
I had inherited the afterEvaluate
block, and I have no idea why it was included. So, if anyone can explain how it could assist in this scenario, I would appreciate it.