It’d be really useful to be able run Gradle in daemon mode, but have it ‘watch’ one or more directories. When a change occurs in one of those directories, it would then trigger a Gradle build with a set of tasks (configurable).
The use case might be: I’m developing a JavaScript browser based app using Backbone.js. I’ve structured all my modules to be in different files, and whenever I change a file in my source tree, I’d like Gradle to automatically notice the change, and trigger a build, which lints my JS, compiles LESS to CSS, uses the r.js optimizer to produce a single .js file, etc. It might also copy the resulting artifacts to a development web server I’m running (restarting if necessary).
Another use case: I’m building a Spring MVC app. I’d like Gradle to automatically build my project when I save changes, so that I can quickly determine when I introduce a breaking change. Admittedly, this use case is a little weaker (who would want to have build failures when you have a partially completed file?).
This indeed would be a useful feature, and is something that we’ve been talking about internally for some time. Unfortunately, it’s not really feasible to do this with Gradle today.
You’ll have to find an external process that watches for changes and kicks of the Gradle build. You could either kick off the Gradle build via the command line, or via the Tooling API.
Thanks for the well written suggestion! What you are describing is a highly desirable feature that has been discussed before and is definitely on our list. The fact that Gradle tasks already know, or can be made to know, all their inputs will make this an even more compelling feature.
Thanks for your comment. I will rework my plugin soon.
In practice, it work correctly.
The most annoying point is that task like ‘compileJava’ return list of java sources as input, not the sourceSets, so hoping to use only task input to declare watches is quite compromised.