when I run war, it creates all the war files I need. But this functionality repeates in at least 2 more projects and I don’t want to duplicate this code all over.
How can I make an “abstract” task, or a task, which takes different $env?
Since Gradle’s build language is based on a general-purpose language, you can use similar strategies as for your production code: generate tasks in a loop, configure multiple tasks with a single configuration block, extract method, extract class, etc. For ‘Copy’ tasks like ‘War’ in particular, there is an additional option, namely to extract common copy logic into a so-called copy spec:
def spec = project.copySpec {
from "foo"
into "bar"
}
war1 {
from "baz"
with spec
}
war2 {
from "other"
with spec
}