Task outputs for lifecycle tasks


(Peter Niederwieser) #1

The following is natural but doesn’t work because the ‘classes’ lifecycle task has no outputs:

jar {

from project(":other").classes

}

If lifecycle tasks were a first-class concept in Gradle, this could be made to work nicely.


(Luke Daley) #2

I’m not sure when you would want to use this.

What use case do you have in mind?


Outputs of C executables are not retrievable
(Peter Niederwieser) #3

You mean this particular example? Embedding the classes of another project in a Jar can be useful (e.g. to only have to ship a single Jar), and above code seems like a natural way to declare it. As a more general answer, it’s hard for users to understand that ‘compileJava’ does have outputs but ‘classes’ doesn’t.


(Luke Daley) #4

It would mean that lifecycle tasks would need knowledge of their “children” though. For example, how do you know what .classes means for all the dependent tasks of ‘classes’?

What might be doable is for lifecycle tasks to expose their dependents…

task allClassFiles(type: Zip) {
   from classes.dependents.withType(Compile)
}

But it’s debatable how much better that is than:

task allClassFiles(type: Zip) {
   from tasks.withType(Compile)
}

Not identical by any means, but I wonder which one would be more common.


(Peter Niederwieser) #5

It would mean that lifecycle tasks would need knowledge of their “children” though.

Well, Gradle already knows about task dependencies. But since we don’t want this behavior for “regular” tasks, it would have to know which tasks are lifecycle tasks.

Not identical by any means, but I wonder which one would be more common.

‘classes’ seems like the obvious choice to refer to the entire compile output of a source set (including resources). My real point though is that it seems generally useful to define the outputs of a lifecycle task as the outputs of its nearest “regular” task dependencies.


(Luke Daley) #6

Just “forwarding” the outputs makes sense I guess.

We don’t really need any more model elements to do this now I don’t think, just a little bit of extra wiring when creating tasks like ‘classes’.