Gradle executes CURL Command after refreshing project

Hello there,

I have created a task that calls Couchbase’s REST service method via CURL. Now, this task flushes the given bucket, effectively deletes every single document.

This is for development purposes and having entire database flushed the moment someone adds dependency or comment to a task in Gradle is not really something we would want.

The task in question looks like this:

task flushBucket() {
    def auth = couchbaseAdmin + ':' + couchbasePassword
    def link = couchbaseIp + ':' + couchbasePort + '/pools/default/buckets/' + couchbaseBucket + '/controller/doFlush'
    ['curl', '-X', 'POST', '-u', auth, link].execute()

Is there a way to stop this from happening? Maybe another way to execute a CURL command?

I believe this has something to do with caching and taking a snapshot of the output. Any way to circumvent this?

Thank you very much for your help.

This is a very common mistake. You’re executing the curl command during the configuration phase, which happens before executing any tasks.

Look at the example build.gradle here to get an idea of what I’m talking about:

You need to wrap your call to curl in a doLast or use an Exec task.

I come from Ant and still learning the ropes. Must have missed it.

Thank you very much!