Hi, i want to share logic between settings.gradle....
# community-support
s
Hi, i want to share logic between settings.gradle.kts and project's build scripts, i managed to write a settings plugin and script plugin in an included build. but it only works if its an included build other then buildSrc, if i put the plugins in buildSrc it doesn't work. i want to share in these two plugins code that i have in buildSrc but its not possible. is there a way to use code from buildSrc in an included build? or , can i safely just rename my buildSrc folder,use it as the included build and put all the plugins there?
v
A very long time ago,
buildSrc
was built before the settings script evaluation and things from
buildSrc
were available in the settings script. But since quite some time this is not the case anymore and
buildSrc
stuff cannot be used in the settings script. You indeed need an included build that is included within
pluginManagement { ... }
to build a settings plugin that can be used.
buildSrc
is always just available for its "parent" build, so an included build cannot use things from
buildSrc
of the including build. At least not without imho dirty tricks like symlinking
buildSrc
into the included build, so that it builds the same
buildSrc
. There are slight and subtle differences between
buildSrc
and an included build, but for great lengths, you can indeed just rename the folder and include it instead. It is mostly edge-cases that only work in one but not the other. For example you can have settings plugins in an included build, but not in
buildSrc
. Things from
buildSrc
are automatically available in all build scripts and thus also invalidate all tasks in all projects if anything changes, things from included builds are only available where they are used. By having the
buildSrc
classes available everywhere you get accessors for plugins generated, with included builds this is not the case - unless you apply a settings plugin from the included build as then the classes are also available in all the build scripts automatically and so the accessors can again be generated, but again everything will be out-of-date if anything changes. With
buildSrc
you can monkey-patch classes from 3rd party plugins, which does not work with included builds. Generally, I prefer using an included build wherever possible, unless I have a good reason to use
buildSrc
, like when monkey-patching is necessary.
s
@Vampire Thank you for the detailed reply. I just renamed buildSrc and used it as includeBuild in pluginManagement { ... } and everything i have there still works and also the settings plugin. So i guess i don't have anything from the edge cases. Thank you!
👌 1