I have a project property that contains a list tha...
# community-support
m
I have a project property that contains a list that I want to iterate over and configure the build accordingly (adding new source sets, configurations, artifacts, etc). Is this the right use case for a custom plugin, or should I just make a task/function to reuse that chunk of build script?
v
How would "just make a task/function to reuse that chunk of build script" look like?
m
It would just be a parameterized way of adding these configs/etc to the build script
v
I mean really concretely. Where would you define what and where and how would you use it?
m
It would be a fun in build.gradle.kts, which would take in a name and a list of sources. On use, it would create a source set, a configuration, a jar task, and an artifact. It would be called multiple times in the initialization phase.
v
Multiple time from within the same build script? That would be "okay" but a bit un-idiomatic, as build scripts should be as declarative as possible, putting imperative logic to custom plugins and tasks. But for a really small and simple logic a local function in the build script that you also only use from that build script would probably be ok. If you want to also call this from subprojects, or worse, use a
subprojects
or
allprojects
closure or similar, then definitely make a convention plugin instead, that you apply directly where you want the effect to be present.
m
Great, thanks so much!