Lazy Configuration (Property) and Task Output

(Brian Keyser) #1

This could be two different questions, but thought I would ask in a single post as they are related.

I have a need to retrieve data from a remote service and have tasks operate on that data. The data from the remote service is provided as a JSON document. Elements within this data are then used by other tasks as inputs. One option is for a task that retrieves the data be represented as an object (to avoid parsing it for each task that uses the data). I understand (some of such as determining when the task is up-to-date) the complications associated with representing an object as a task output. Is the preferred approach to store the document as an output file with the tasks that use this data having to parse it each time?

The second question surrounds the use of lazy configuration. Suppose that, from the root project, there is subproject A that retrieves the data and subprojects B and C that use the data. My understanding with lazy configuration is that within project A a RegularFileProperty could be declared

RegularFileProperty dataFile = newOutputFile()

and then within subproject B and C that would declare a dependency on the data file of subproject A

def dataRetrievalTask = project.tasks.findByPath(':a:dataRetriever')

 task useDataInProjectB(type: SomeType) {
      inputData = dataRetrievalTask.dataFile

I have noticed in this case that the tasks are not automatically wired together. Instead, I must use an explicit dependency declaration

task useDataInProjectB(type: SomeType, dependsOn: ':a:dataRetriever') {
    inputData = dataRetrievalTask.dataFile

I had originally had projects B and C in a single project and the multiple tasks did not require the explicit dependency.

Thanks in advance for your help