Hey how can I split configuration of a plugin thro...
# gradle
a
Hey how can I split configuration of a plugin through multiple build.gradle.kts scripts? I have to configure different types and want to have a file that simply exports that config for a certain type then include all the subscripts in the build.gradle.kts Is the only way to do this with buildSrc or can I use apply from?
Also can I have buildSrc folder in submodules?
v
You can surely use regular script plugins (
apply from
), but I wouldn't ever use them these days, especially not with Kotlin DSL as you don't get type-safe accessors generated for them. The way better option is to use pre-compiled script plugins (
foo.gradle.kts
in
buildSrc
or - what I greatly prefer - in an included build like
gradle/build-logic
).
Also can I have buildSrc folder in submodules?
You can have a
buildSrc
folder wherever you like, but for it being what you meant, no, unless the submodules are own builds in a composite build and not subprojects. You can have exactly one
buildSrc
project which is run before the main build and added to the class path of all build scripts. But if you use included builds instead as I mentioned above, you can have multiple ones, whyever you would want to do that. But you still need a settings script and thus an "own" build to include them. But again, the question is why you want that. Depending on the answer there might be better options.
a
I want to separate the configs because they’re are quite large for different components and would like to split them
v
Yeah, but why multiple projects for that and not simply different precompiled script plugins in one project?
a
for example I have my application submodule and a nft application submodule both in my project and I need configurations for a couple components in both submodules
and wanted to split that logic across multiple scripts
also to avoid having to apply the same plugin in all the scripts and rewrite the configure block of that plugin
v
That still does not answer the question why you think you need / want multiple projects for your convention plugins, instead of just having them in one project. Your use-case is exactly what convention plugins are for, and especially when written as precompiled script plugins.