-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I use Gratatouille to write task actions with side-effects? #22
Comments
That's an excellent question and I haven't put too much thoughts into it. At first sight, I'd say this is currently not working because |
Thanks for the reply! Actually let me amend what I said. The task fetches information from GitHub and produces a changelog file as an output. So there is an output, but part of the input comes from the internet, so it can never be up to date. |
Thanks for the follow up! Am I correct that this is about allowing non-pure functions? You would still use Gratatouille for parallel execution (all the workers boilerplate), non-overlapping outputs, potentially classloader isolation but with non-pure functions? I think this makes sense. One could for an example use the output of What about adding User code: @GTaskAction
@GNonPure
internal fun computeChangelog(output: GOutputFile) {
TODO()
} Generated code: // Note no @CacheableTask here
internal abstract class GenerateChangelogTask : DefaultTask() {
init {
outputs.upToDateWhen {
false
}
}
@get:OutputFile
val output: RegularFileProperty
}
// Worker, etc... Thoughts? |
Yes, I believe we can frame it this way. I opened this issue because the section of the docs about pure functions seemed to mentioned this as a kind of requirement (even though it's in the "features" section). So, with that in mind, your suggestion looks good to me, but please keep in mind that I don't know all the implications, so my opinion might not bring much value on this 😅 |
I have added a It can be used like so: @GTaskAction(pure = false)
internal fun impureFunction(
input: String,
outputFile: GOutputFile,
) {
outputFile.writeText("${Date()}: $input")
} |
Oh nice! Thank you! |
By the way, no rush at all, this is just a side project, and I wanted to clean it up also as an excuse to try Gratatouille. I'll give it a go when you cut a release ;) |
Sounds like a plan 👍 Heads up the project is still in the early days. I haven't used it in a real life plugin yet. I want to use it in Apollo at some point but there are still some deprecated features that would be awkward to use with Gratatouille (because they require internal properties and using the global classpath, namely Hopefully in 2025 🤞 |
Description
I would like to try to use Gratatouille to make the Gradle GitHub Changelog plugin more correct without adding too much boilerplate.
This plugin fetches GitHub issues information from GitHub during the task execution, which is inherently a non-cacheable side-effect. Can Gratatouille be used for this too?
The text was updated successfully, but these errors were encountered: