This message was deleted.
# configuration-cache
s
This message was deleted.
c
Simplest reproducer I could come up with
c
hmmm. that error message appears to be more about the Task object itself, rather than what may be captured. Do you have the full stack trace?
thx. what does the build.gradle look like? (presumably this is where the custom task is registered)
c
Yes, of course. This was generated with the standard GradleRunner test the gradle init spits out
So the functional test example generated by gradle looks like
Copy code
buildFile << """
plugins {
    id('gradle.plugin.closure.issue.greeting')
}
"""
And the plugin registers it’s tasks like
Copy code
project.tasks.register("issue", GradlePluginClosureIssueTask) { GradlePluginClosureIssueTask task ->
            task.doLast {
                println("Ran gradle issue task")
            }
        }
c
ah, groovy. try this:
Copy code
project.tasks.register("issue", GradlePluginClosureIssueTask) {  task ->
            task.doLast {
                println("Ran gradle issue task")
            }
        }
c
That didn’t seem to help
the
Copy code
at gradle.plugin.closure.issue.GradlePluginClosureIssueTask$_closure1.doCall(GradlePluginClosureIssueTask.groovy:14)
line is
Copy code
if (getSomeData() != null) {
in the task
c
The configuration closure doesn’t need lambda syntax.
Copy code
project.tasks.register("issue", GradlePluginClosureIssueTask) {  
            doLast {
                println("Ran gradle issue task")
            }
        }
c
It did in this tasks case since I have the
@CompileStatic
annotation on the plugin. Removing it made the compiler error go away, but not the task cast error
Oh, ok so I removed the CompileStatic from the task as well, and got a different error.
Copy code
> Could not find method getSomeData() for arguments [] on task ':issue' of type gradle.plugin.closure.issue.GradlePluginClosureIssueTask.
c
ah, ok. interesting. the method is there, though it’s called inside other closures. Is that the only call to it (in the constructor)?
c
In this trivial example, yes. In a plugin I’m working on no
c
possible to rework your trivial example to use Kotlin? It offers far better type-safety and helpful error messages for cases like this.
c
The trivial example looks like it works when I rewrote it in java at least
c
cool. likely some subtle Groovy-ism there then.
c
bmushko’s gradle docker plugin is massive and written in groovy tho, which makes a rewrite a bit more daunting 😉
c
yea. have incrementally moved a few plugins from groovy to Kotlin. First step is to ensure you use Action<WhateverClass> instead of Closure - this helps both with interop within the plugin, and ease of use for Kotlin DSL consumers of the plugin (they shouldn’t have to see the Groovy closure stuff).
See https://github.com/allegro/axion-release-plugin as an example of mixing Groovy and Kotlin.
c
Thanks for the help!
👍 1
At least for this task, I was trying to get a reproducer together to maybe report to the gradle team.
c
totally. glad you’re making progress!
c
Ok so I’ve got one more workaround now
Copy code
outputs.upToDateWhen {
by default in groovy that syntax will call the Closure override
If you write a similar call in java or kotlin, it’ll choose the Spec<Task> functional interface override instead
Manually specifying
Copy code
outputs.upToDateWhen(new Spec<Task> { .......
in groovy makes the whole thing work
c
interesting. Does this (or some variation) work:
Copy code
outputs.upToDateWhen( Spec<Task> {
lol. yep.
you may also be able to cast it to get the right override.
c
I tried the most groovy-esque equivalent I could find which was
Copy code
outputs.upToDateWhen {
} as Spec<Task>
and that failed too
c
Spec<Task>?
c
yahp
also tried
Copy code
Spec<Task> upToDateWhen = { Task task ->
    if (getSomeData() != null) {
        return true
    }
    false
}
outputs.upToDateWhen(upToDateWhen)
which pretty much makes up every syntactical variation I could come up with
c
yea. unfortunately that’s beyond my Groovy-fu, haven’t touched it much in a couple of years.
c
Appreciate the rubberduck regardless.
👍 1