How do I save state between task runs?

(Meikel Brandmeyer) #1

I have a task which generates files in a two step process. I want to keep the files of the intermediate steps between task runs (incremental changes). However I don’t want to include them in any artifact. But still, I’d like to clean them when I run the clean rule for the given task. Is there a way to accomplish that?

(Peter Niederwieser) #2

What exactly do you mean by “a task which generates files in a two step process”?

(Meikel Brandmeyer) #3

It’s ClojureScript compilation. First it is compiled down to javascript. Then this output is sent through the google closure compiler to create the final output. Interesting is only the latter (’@OutputDirectory’). But I’d like to keep the former around for incremental compilation. Adding it as ‘OutputDirectory’ would add it to task cleaning and update-to-date checks. But that’s not what I want, since it’s only some intermediate state.

(Peter Niederwieser) #4

If you want to model this as two separate tasks, and you want to have up-to-date checks for both of them, there is no way around declaring the outputs of both tasks (and the outputs of the first task will become inputs to the second task). Why are you trying to avoid this?

(Meikel Brandmeyer) #5

Ok. I did a bad job at explaining my question. Reset.

The ClojureScript compiler creates several intermediate files before compiling the final javascript assembly. Both steps are one single invokation of the cljs compiler. I don’t want to the intermediate files to be part of the source set output, since they are not relevant. I do want to have the cleaned by the compile task’s clean rule, though.

                  <-- This source is
             <-- compiled to js here, which in turn
  <-- is compiled to a different, single js file here.

The last directory is marked as ‘@OutputDirectory’ and is part of the source set output. The middle directory is only task internal, but not temporary. It should stay there between task runs to enable incremental compilation. However it is also not removed by a ‘cleanCompileClojureScript’, which might cause troubles with stale files.

(Meikel Brandmeyer) #6

Can I simply define my own ‘cleanClojureScriptCompile’ task? It could do the right thing.

Would this clash with the task rule?

(Peter Niederwieser) #7

You should be able to configure the existing clean task (which has type ‘Delete’). Or you could make ‘cljs’ write the intermediary files to a temporary directory (e.g. ‘Task.temporaryDir’). Using a separate ‘@OutputDirectory’ for the intermediate files should work as well, as this shouldn’t automatically make them part of the source set output. Still, it’s probably not a good idea to declare intermediate files as outputs.