On 29/07/2011, at 7:22 AM, phil swenson wrote:
> Is there anyway I could override gradle's up-to-date functionality?
>
> I have two scenarios in mind
> 1) I need to call a web service, pass in the last message ID from
> previous run, and check to see if it is the latest. If there is new
> info, then the task is not "up to date" and I need to execute the task
A couple of options:
You can use the outputs.upToDateWhen() method:
myTask {
def newValue
outputs.upToDateWhen {
def oldValue = loadValueFromSomePersistentStorage()
newValue = fetchNewValueFromWebService()
return oldValue == newValue
}
doFirst {
writeValueToSomePersistentStorage(newValue)
}
}
If you have a task type, you can simplify this to:
class MyTask extends DefaultTask {
@Input
String getMessageId() {
return fetchNewValueFromWebService() // might want to cache this value
in a field
}
}
Gradle will take care of persisting the value and doing the comparison for you.
>
> 2) if someone changes the configuration for a task (by this I mean a
> properties file or a convention), then I want to re-run.
You have the same options as above: use an upToDateWhen { } predicate, or
expose the configuration as a property or properties marked with @Input.
--
Adam Murdoch
Gradle Co-founder
http://www.gradle.org
VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
http://www.gradleware.com