Am I able to say write a kotlin function in that c...
# community-support
n
Am I able to say write a kotlin function in that can be used by any subproject in my project without it being wrapped up in a plugin? I've tried creating a build
build-logic
that I include into the main project with
includeBuild
In it I have an empty function
test()
and the IDE doesn't display any errors when using it in my other build scripts but when I try a gradle sync it's an unresolved reference
e
you have to add it to the buildscript classpath somehow. if not a plugin, then
Copy code
buildscript {
  dependencies {
    classpath(":build-logic:unspecified")
or whatever to match the coordinates in your build-logic project
includeBuild
makes it possible to include as a buildscript or plugin dependency, it doesn't automatically do so.
but it's super easy to add an empty plugin even if you don't want to go through the plugin process, that'll bring the rest of the project into the buildscript classpath
t
…or use
buildSrc
that's guaranteed to be added in the build classpath
n
I suppose
buildSrc
will work. I've however seen things advising against using buildSrc
I wanna also ask how to properly add implementations of plugins in my buildSrc dependencies configuration? Is there some way I can just use the same
<http://libs.plugins.xyz|libs.plugins.xyz>
that I can use in the plugins block or do i need to explictly add an additional library for each plugin in my version catalog?
t
See https://github.com/gradle/gradle/issues/17963, there are many workarounds in the comments and linked issues; I use:
Copy code
fun plugin(plugin: Provider<PluginDependency>) = plugin.map { "${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}" }
n
Oh neat. I changed it up so i can just use plugins directly
Copy code
fun DependencyHandler.implementation(dependency: Provider<PluginDependency>) {
    implementation(dependency.map { "${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}" })
}
Thank you!