Niels Doucet
11/17/2025, 1:38 PMcopySpec that only defines exclusions (with exclude) and I'd like to reuse it in multiple tasks that have differing from clauses.
Is there a way to do so?
(more details in ๐งต )Niels Doucet
11/17/2025, 1:39 PMwith(reusableCopySpec) on the root copy task, but that registers a new child spec without any from clause, so it doesn't apply to anything.
I also tried:
with(reusableCopySpec.from(<task-specific input>))
but that changes the state of the copySpec itself, leading to every task that reuses it to have all inputs from all tasks.Vampire
11/17/2025, 1:54 PMCopySpec is what you should use there.
Iirc the copy spec is self-contained, so defines some from and for those excludes and you can reuse it.
If you want to reuse excludes like that, you should probably store the configuration block and reuse that in the other copyspecs where you use the from.Vampire
11/17/2025, 1:56 PMval foo: CopySpec.() -> Unit = {
exclude("...")
}
tasks.jar {
from("...") {
foo()
}
}Vampire
11/17/2025, 1:56 PMfun CopySpec.foo() {
exclude("...")
}
tasks.jar {
from("...") {
foo()
}
}Niels Doucet
11/17/2025, 2:02 PMCopySpec.() -> Unit signature at some point, but I must've done something wrong when applying it.