Reputation: 19798
I have the following:
task cloneProtobuf(type: Exec) {
workingDir "${rootProject.buildDir}/github.com/google"
commandLine 'git', 'clone', 'https://github.com/google/protobuf.git'
enabled = { -> !new File(workingDir, "protobuf/.git").isDirectory() }()
doFirst {
mkdir workingDir
}
}
Rather than explicitly setting enabled
and having gradle indicate that the task was SKIPPED
, I would rather have gradle consider that if the protobuf
directory already exists, the task is UP-TO-DATE
. How can this be done?
Upvotes: 2
Views: 2686
Reputation: 84864
Instead of enable/disable a task, please register a task output, then gradle will be aware itself if a task is up-to-date or not. Please have a look at the example below which you can find helpful:
task mk(type: Exec) {
def output = project.file('mk')
outputs.dir output
commandLine 'mkdir', output
workingDir '.'
}
If you run gradle mk
twice, the task will execute only once.
Upvotes: 2