DEV Community

Discussion on: Gradle plugins and extensions: A primer for the bemused

Collapse
 
autonomousapps profile image
Tony Robalik

For sharing information between tasks, I rely entirely on writing output to disk. I don't think any of Gradle's @Output... annotations support non-File types. In your case, I would just write the String to disk in a file that was pointed to by @get:OutputFile abstract val output: RegularFileProperty and then use that output as a file input to the other task. You could write it to disk however you like, but I normally use moshi + json.

Collapse
 
martinbonnin profile image
Martin Bonnin

Yep, sorry String was a bad example. The question was about exposing internal Properties.

Assuming you have an @get:OutputFile val outputFile: RegularFileProperty, how do you forward that to other parts of the build? I find it somewhat convenient to expose the outputFile itself which then makes it possible to set it without going through the functions and disallowChanges. Maybe not a huge problem but I bumped into this lately and wasn't sure if there was a more idiomatic way.

Thread Thread
 
autonomousapps profile image
Tony Robalik

I think that disallowChanges() is more for user-facing API. I do what you're suggesting all the time. E.g., in a task configuration block:

consumerTask.someInputFile.set(producerTask.flatMap { it.someOutputFile })
Enter fullscreen mode Exit fullscreen mode

Those properties aren't meant to be used by users, so if they mess with the properties, that's on them, Undefined Behavior.

Thread Thread
 
martinbonnin profile image
Martin Bonnin

I see, thanks!