I have a mixed groovy/kts project and I have a que...
# gradle
k
I have a mixed groovy/kts project and I have a question around interaction between kts and non kts build files: I created a buildSrc project with the
buildSrc/build.gradle.kts
. I'd like to access the values (ext or otherwise) and functions from the root/top-level project's groovy-based
build.gradle
. What's the best way to do so?
v
That's not about Groovy vs. Kotlin. What you want to do simply is not possible. Using
ext
properties per-se is usually already bad practice, as it usually is just a work-around for doing something not properly. But besides that,
buildSrc
is a separate build that is run before your build even starts, so you can hardly access the main project's build model from the
buildSrc
build script. If you want to share some build logic, put it to a separate build, that you then
includeBuild
and use where you need it.
k
thank you - so buildSrc is the first thing that runs whenever you run any gradle build in the project before the rest of gradle?
v
Yes
Well, no, the settings script runs before
That's why you can't use
buildSrc
classes in settings scripts anymore since a few years
k
thank you for that insight, is this has been really useful
👌 1