Hey all, how to write some utility functions in kt...
# gradle
g
Hey all, how to write some utility functions in kts (e.g. function reading some data from a file) and use them from build.gradle? How to import such a kts file from build.gradle?
s
You can also use a script plugin, but I’m not sure how well it works with Kotlin build scripts. I don’t think you can put a function in a script plugin and then call it from the main Kotlin build script.
m
Just make an included build
It's a tiny bit more to setup but more flexible than
buildSrc
g
hmm, would that help me to expose symbols (e.g. these functions I mentioned) to the build.gradle closures?
m
You'll have to put the included build in your classpath:
Copy code
plugins {
  id("my.convention.plugin").apply(false)
}
Then you can call all functions from your included build. Once you start requiring doing something automatic, remove
apply(false)
and you can have automatic processing
247 Views