I have some helper functions inside `*.kt` files i...
# gradle
n
I have some helper functions inside
*.kt
files in my
build-logic
project that I use in convention plugins. It’s something like
fun Project.doSomething()
and I want to use them in my
app/build.gradle.kts
as well. Is it possible to achieve somehow?
w
Gradle's
buildSrc
directory might be what you're looking for. Basically, it's for any code you want to add to the build itself. You can use it to define little helper functions up to full fledged project specific gradle plugins: https://docs.gradle.org/current/userguide/organizing_gradle_projects.html#sec:build_sources
a
Yes, it's possible. When using buildSrc any util functions will be available in all scripts, even if you don't apply a plugin in the build scripts. If you use an included build instead of buildSrc then you need to apply a plugin (even if it's an noop one!) to access the util functions. I normally create a convention plugin like
build-logic/src/main/kotlin/my-cool-project-base.gradle.kts
that contains conventions for all subprojects, and apply it to all subprojects.
e
anything that brings it into the buildscript classpath will work - you can even create an empty plugin in
build-logic
and apply it, or pull in an existing plugin (possibly with
apply false
), or use the old
buildscript.dependencies.classpath