This question was originally posted on the old forum and now copied here:
I’m trying to store results in a set of properties or an object from the execution of one Gradle task so I can then pass these results into another task. In other words, I’m trying to work with Gradle tasks as with methods where a method can have a return value of an Object, and a calling method can then get hold of that return value.
I don’t know if this is an advisable approach or not, but I’m not finding much information on that in the Gradle’s user guide. The only information I find is Gradle tasks have inputs and outputs, but these are handled via directories and files, and I don’t want to go through this kind of setup for what appears to be an easy thing I’m trying to accomplish.
Does anyone have any ideas on this?
That’s generally not the kind of thing that you do in Gradle, but that’s not saying it’s not a good way to solve your problem.
Are you able to give some more information about what your tasks do and what you are trying to achieve? That will help to get to the best solution.
Principal Engineer, Gradleware
In my Custom ReadEnvironmentInfoTask I’m reading various properties files containing connectivity information to a database, and I then connect to that database and query couple of fields for the information which should then drive further conditional logic of the build.
So, my intent for this ReadEnvironmentInfoTask (custom task) was to connect to a database and store described information either in a set of properties or even encapsulate it in a Groovy object which the (other) calling task could then get hold of and further direct the logic of the build. This way I was trying to encapsulate all of the logic for reading propertis files and connecting to a database for furher information in one task and then have other tasks act on such retrieved information and proceed further.
Hope that explains better of what I’m trying to do.