https://kotlinlang.org logo
#scripting
Title
# scripting
e

elect

07/12/2022, 8:30 PM
I've watched the

talk

of Oliveira to the Kotlin Conf and I wonder if I may be able to implement something Gradle-like, where you have a
plugins
block which gets evaluated and based on its content, specific code would be generated and made available to the rest of the script. In Gradle you have to hit refresh in the Gradle window, in order to trigger this mechanism, but what about in a classic script instead?
j

Javier

07/12/2022, 10:31 PM
I think they have its own compiler plugin for that
e

elect

07/12/2022, 10:54 PM
may I ask what suggests you that?
j

Javier

07/12/2022, 11:11 PM
What you mean?
e

elect

07/13/2022, 5:38 AM
why do you think they use a compiler plugin
e

efemoney

07/19/2022, 2:34 PM
Not a compiler plugin but they parse the source code “manually” (not with regex or anything but via a kotlin lexer)
i

ilya.chernikov

07/20/2022, 7:02 AM
There is a callback mechanism in the scripting API (
refineConfigurationBeforeParsing
property in the configuration) that would allow you to "intercept" the compilation in order to process your variant of the
plugins
block and supply the results (most importantly - new dependencies) to the compilation of the original script. But there are no means yet that would help you to process the block, you'll need to parse the script on your own. I do not recommend using compiler internals for that, like the lexer, while it may not be available for you in the future.
👍🏾 1
👍 1
8 Views