Hey all. I'm currently having some issues trying ...
# gradle
n
Hey all. I'm currently having some issues trying to apply a gradle plugin written in Groovy from my kts gradle script (Note: I do not have the ability to tweak the groovy code). Basically it seems like the groovy plugin is configured to need to see a particular method on the root project which it tries to call. So I basically get errors like: Could not find method foo() for arguments [] on root project 'my_root_project_name' of type org.gradle.api.Project I've tried defining my own function like "fun foo() ..." various places in my kts script, but no matter what I do, Groovy can't find it. Does anyone have a workaround for issues like this?
m
Sounds like this could help?
plugin is configured to need to see a particular method on the root project which it tries to call.
If you can get the signature of that method (whether a Groovy closure is expected or something else), that'll help
n
I'll give that a shot! I just realized that in Groovy scripts that use this plugin, foo is defined as: ext.foo = { ... } So I guess that is a groovy closure, not a function.
m
Maybe something like so?
Copy code
extra.properties["foo"] = closureOf<Project> {
  // Do stuff here
}
Not an expert by any means but I have been bitten by this a couple of times
v
Or
Copy code
val foo by extra {
    closureOf<Project> {
        ...
    }
}
Besides that this plugin should probably be fixed of using such hacks 😄
☝️ 1
☝🏾 1
n
It did seem very hacky to me. 😂 Out of curiosity, what's a less hacky way to do something like this? Unfortunately I don't think I could convince the maintainer to move to Kotlin, but maybe they'd accept a MR.
v
What you need to assign the extra property to depends on what the plugin expects. Maybe also something like
Copy code
val foo by extra {
    KotlinClosure1<String, Unit> ...
}
Out of curiosity, what's a less hacky way to do something like this?
Basically, almost anything that uses
extra
or
ext
is hacky and just some work-around for not doing it properly.
That maintainer does not need to switch to Kotlin, he just have to do it properly. 😄
How that properly would look like depends on what that plugin needs / does. Impossible to guess without knowing what this is actually about.
But probably the plugin would instead register some extension with a method taking an
Action<...>
as parameter that is then used as callback instead of requiring to set some
extra
property to a Groovy closure.
n
Hmm... Well I've made some progress and gotten another error. It's complaining about a $receiver for Build_gradle$1$1$1.invoke is null for some reason.
Same error for either the KotlinClosure or closureOf
v
Well, as said, what you have to give there highly depends on what that plugin is expecting you to deliver. We can hardly guess.
n
Yeah, I'm just not sure how the receiver would be null. Unhelpfully the stack trace doesn't actually go down into the plugin code for some reason.
v
🤷‍♂️
n
Welcome to Gradle, lol.
v
That has nothing to do with Gradle. It's just a badly designed 3rd party plugin.
1
n
This is just my experience with Gradle in general. Maybe Groovy is the true culprit, not Gradle -- but the issue is obtuse error messages with little to no help for the developer in actually figuring out what the issue is. The plugin itself may be bad, but that's still a framework problem IMHO. The framework should provide easily accessible tools allowing the developer to debug even bad code (See Rust's error messages for instance). After all, more often than not, that's what needs debugging.
But I think after changing the type of my receiver to nullable I have solved the problem. Thank you for your help!
👌 1
💙 1