Hi,
I have written a simple task that performs a clean if the main version changes.
This is not something that happens very often (4 times a year), but it can be a
timeconsuming hassle if a developer forgets to do it locally. In addition, we
have many different bamboo plans that are affected (x2, since they're running
on 2 different servers), which today needs to be manually cleaned.
The task currently looks like this:
task cleanWhenMainVersionChange {
inputs.properties(["mainVersion": mainVersion])
outputs.files file("$buildDir/cleanWhenMainVersionChange.txt")
doLast {
clean.execute()
}
}
To work properly, this code needs to be used in 4 different multiprojects, with
a varying number of tasks being performed for each sub-project. We want to
ensure that this task is the first to run.
The only way I am aware of to do this, is by setting dependencies. However,
since there are several different tasks that have the potential to be first, we
have to set dependencies from all of them to the "cleanWhenMainVersionChange"
task.
Is there a simpler way to do this, preferably one where we don't need to know
about all the tasks that have the potential to be executed first?
Finally; a question regarding outputs:
If I don't declare any outputs, the task is executed every time. Running with
the debug flag reveals that gradle considers any task with no outputs declared
to never be up-to-date.
However, as you can see, I don't need to actually create the file - only the
output declaration. It seems to work as intended if I don't create the file;
i.e. it is only performed if the mainVersion property is changed.
Is this intended? If so, why do we need to specify the outputs declaration here?
Thanks in advance for any reply.
Regards,
Steinar Haugen