I'm using the shadowJar
plugin for Gradle (4.2.1) to build the so-called fatJar
or uberJar
. This works as expected but I would like to to add some actions after the building is done. More precisely, I'd like to make the resulting file executable (in Unix
terms, i.e. chmod +x
) and then copy it to a certain directory. I've googled a lot and I know that both task are possible. I'd like to know whether I should write a script (task) that runs shadowJar
and then does what I want, or I should change the shadowJar
itself to embed the operations I need.
I think a good criteria to decide about such situation is to ask yourself if the new features are really part of the responsibility of the shoadowJar
. If the answer is no, then it would be better to (as you mentioned) have another task that runs on top of that. By doing so you can reuse the shadowJar
in much more different scenarios by combining it to other tasks. If you define the new one to be dependent on the shadowJar
, then you would be sure that you can still call shadowJar
task individually while calling the new task would always trigger the shadowJar
. Your new task would be something like this:
task afterShadowJar (dependesOn: 'shadowJar') {
// manipulate file permissions, etc.
}