This message was deleted.
# plugin-development
s
This message was deleted.
e
m
Is that related to the implementation language of the plugin? I would expect the plugin language to be irrelevant here and this to be a
build.gradle
vs
build.gradke.kts
thing
Unless it's a precompiled script plugin I guess
k
actually this question comes from spotbugs-gradle-plugin, not precompiled script plugin
I would expect the plugin language to be irrelevant here and this to be a
build.gradle
vs
build.gradke.kts
thing
sad to say but plugin language matters...
a
it should be possible using the new Kotlin Assignment overloading plugin (which is available in Gradle v8.2+ I think) Just define this extension function:
Copy code
fun Property<Values>.assign(value: String) {
  set(Values.valueOf(value))
}
👀 1
k
I'll check this 👀
a
Ahh yeah, that's the one! Here's some non-Gradle specific info: https://stackoverflow.com/q/76022932/4161471. The only difference for Gradle scripts is that the Kotlin Assignment plugin is automatically available in Gradle 8.2+, so you don't need to worry about applying it. Also, the
Property<>
interface has an annotation so assignment overloading is available.
🎉 1
this extension function would probably work for all enums, but I would recommend not doing it, because it will interfere with all other
Property<Enum<>>
properties from all other plugins, which will probably cause issues
Copy code
inline fun <reified T: Enum<T>>Property<T>.assign(value: String) {
  val enumValue = enumValueOf<T>(value)
  set(enumValue)
}
k
Confirmed that the mcve works well. Thank you!
👍 1
🚀 1
m
sad to say but plugin language matters
I don't think it does? At the end of the day, a plugin is a .jar file with a
Property<Values>
field. Whether that plugin is written in Groovy or Java or Kotlin, the bytecode is the same
What you're doing here is that you're adding Kotlin metadata on top of your
plugin.jar
bytecode to "help" the Kotlin consumers (
build.gradle.kts
)
I'd argue this is not always helping because now your plugin is "bound" to the Gradle embedded Kotlin version and behaves differently for
build.gradle
vs
build.gradle.kts
usages
👍 1
Same kind of things for
fun foo(action: Action<T>)
. You could define overloaded
fun foo(action: (T) -> Unit)
but I find it's adding noise to the API. Which function are you now calling?
All in all, trying to make Kotlin syntax look like Groovy is a mistake IMO. If I'm a Kotlin dev I want to write Kotlin, not some Groovy flavour of Kotlin relying on multiple compiler plugins
👍 1
Thanks for coming to my TED talk 🙂