But I’ve got one test scenario which I could need some suggestion how to fix that in a proper way.
At the moment it is (still) done with dependsOn and finalizers where this graph is built:
startComposeStack CS
run a NpmTask A from Gradle to prepare resources (which e.g. makes some rest calls to the compose stack)
run a Gradle Sync task B, to sync some of those resources to a required destination
run the actual test NpmTask C
run the finalizer to stop the composeStack CE
Now with the buildServices above my testTask would look like:
task<NpmTask>(“test”) {
val buildService = extension.buildService
doFirst {
buildService.startUpComposeStack(..)
}
... actual task staff C ...
usesServices(buildService)
// shutdown will be done via TaskFinishedEvent
}
So running the compose stack and stopping would be done via the buildService, so task CS and CE are covered, the actual test task C is the body of the “test” task - but how can I integrate A (resource preparation) + B (Sync) in this scenario?
Is there a way to have something like:
task<NpmTask>(“test”) {
val buildService = extension.buildService
doFirst {
buildService.startUpComposeStack(..)
tasks.named("A").actions.run()
tasks.named("B").actions.run()
}
... actual task staff C ...
usesServices(buildService)
}
If not or is this is not how it should be done, how would such a thing be composed with Gradle?
No, you cannot manually run a task in Gradle.
You would probably either do what A and B does as part of test or as part of the service implementation,
or maybe start it in doFirst of A and shut it down after C is finished.
Not sure, never tried it with that pattern.
If you don’t care about configuration cache, just use sync { ... }.
If you do care about CC, acquire a FileSystemOperations service instance and use sync { ... } on that.
With a custom task you could just get it injected, when just adding an ad-hoc action to an existing task you need for example
Oh many thanks for that sample - I did not know the the fs provider does expose the sync too, that should make things easier than expected. The NpmTask I can replace with a plain providers.exec(..) call and with the sync on the fileSystemOperations - it should be possible to remove those 2 tasks A + B and be back to the buildService solution which works already - I’ll try that.
As stdout and stderr text outputs are only available after the command has finished - is there an example of a ValueSource or a ready to use Gradle ?? provider or … to be able to stream those to the Gradle console output while it is running - I’ve searched the docs but did not yet find such a thing.
providerFactory.exec is more intended for cases where you then provide the output or something from the execution as Provider to some task input or similar which is then evaluated late, and the output is not available in a streamed way but only via the result provider.
If you want more an Exec / exec behavior, what you wanted to use was ExecOperations.exec.