Calling a task in a loop

Hey everyone,

As part of our gradle build we launch a webapp runner (tomcat), that executes against an exploded war. I would like to create a task that infintely calls a Copy task to update the resources in the deployed/exploded war with whatever is in a set of project’s web-app directories.

I tried something like :

task copyUI(type: Copy) {
    into "${buildDir}/exploded"
    from "${project(':someproject').projectDir}/src/main/webapp"
}
  task copyUIRepeat() << {
    while (true){
        println "copying UI"
        tasks.copyUI.execute()
    }
}

but I get ‘The task artifact state cache {foo} has not been locked.’

I see I’m not supposed to call execute, but I’m not sure how else to accomplish this sort of behavior. Suggestions?

Take a look at Project.copy. That way you don’t need to use a Copy task.

Daz’s solution is the simplest.

Another solution is an external build script that calls the gradle build in a loop.

We have plans to offer built in support for this kind of thing (we call it continuously-up-to-date) but it’s a little bit away.

Thanks guys, I’m going with Project.copy as that seems to work fine for the most part.

Here’s one thing I’ve noticed that’s kind of unrelated but I might as well mention here as I’m not sure it warrants much discussion:

In the scenario I’ve described I initially have one gradle task running that never completes (running the web-app via an exec task). I can run a second task concurrently (my continuously up-to-date sync task), but if I change the build.gradle file and try to run the sync task it locks and will not proceed. Edge case I guess.