I have a `buildSrc` folder and `my-plugin` , the l...
# community-support
m
I have a
buildSrc
folder and
my-plugin
, the latter being included with includeBuild. I have a
common.gradle.kts
in my buildSrc, but if I try to add
plugins { id("my-plugin-id") }
, I get
Plugin [id: 'my-plugin-id'] was not found in any of the following sources:
How do I fix this? I tried merging my-plugin with it, but because the plugin depends on kapt and kotlin-compiler-embeddable and such it ended up giving all sorts of gradle/kotlin errors. I also couldn't do
implementation(project("../my-plugin"))
it seems.
v
The
buildSrc
results and dependencies are on a parent classloader of the build script class paths, so it most probably simply cannot see the plugin that lives on a child classloader. You could probably depend on the plugin from
buildSrc
as dependency so that it also lands on that class loader, or you switch
buildSrc
to a proper included build, so that it ends up on the same classloader as the other plugin.
m
I tried moving buildSrc to a new
build-plugin
directory, but now all of my plugins require me to specify the plugin version again instead of using the version specified in buildSrc. Is there an easy way to reuse the versions from the now
build-plugin
folder?
v
buildSrc
is always a bit special and always a bit awkward in what it does. It takes all its result and all its dependencies and puts them on a classloader that is the parent of all buildscript classloaders. With doing so, the content and dependencies are automatically available in all build scripts, but also if you change anything in
buildSrc
each and every build script will be out-of-date and most probably each and every task. If you use a proper included build, then it is like with any other dependency / plugin too. It is only present in the build script of the project where you actually apply a plugin from it or manually add it to the classpath. So you could for example apply a plugin from it to the root project, or declare in the root project a buildscript dependency on that included build's project, then it and all the dependencies make it to the root project classpath and thus also all other project classpaths.
m
For now I've just specified versions, but it's reporting it can't find common in `plugins {
common
}` despite nothing else about build-plugin being different from how it was in buildSrc
v
The type-safe accessors are only there if the plugin is in a parent classloader. If you have the plugin in the
buildSrc
class loader, it is avaiable in a parent classloader and so the accessors are there for all projects. If you have the plugin in the settings script classpath, it is also a parent of the build script classloaders. But if you add the plugin to the root project classpath, the accessors are not available in the root project build script. So easiest is, just use
plugins { id("common") }
, or add the plugin to a parent classloader if you insist on the accessors.
m
build-plugin and my-plugin are siblings, but it seems the build-plugin's common.gradle.kts still can't see
id("my-plugin-id")
even though both are `includeBuild`ed, do I need to move my-plugin as child of build-plugin and include it in a nested settings.gradle.kts?
v
It's hard to read on this level theoretic, an MCVE would really help for the conversation. You probably still miss a dependency from the convention plugin to the plugin you want to apply. A plugin does not automatically land on any classpath, just because you include its buid. If an include build is nowhere used, it is not even built.
m
Right, that missing dependency is what I meant. Is there any way to do that between sibling projects or does it need to be a child project?
v
They are not sibling projects, they are sibling builds. I think you can just additionally also
includeBuild
the my-plugin in the build-plugin and then declare a dependency as usual.