I’m trying to use the Distribution plugin (Gradle 1.12) and (of course), I need to customize some of its operations but I can’t seem to make my customization work.
The first thing I need is to customize the root folder in the archive. Say I want to call it “rootFolder” for example instead of the default generated name (let’s call it defaultRootFolder to make this description more simple).
I looked in the source code at how the distribution tasks are created, and it appears that in my build script, I can access them and change their configuration.
The first thing I tried was:
tasks.windowsDistTar.into(‘rootFolder’)
When I do that, I correctly have the root folder of my archive called ‘rootFolder’, which is great, but inside, there is an extra folder called ‘defaultRootFolder’. I wondered how this could happen and looked at the source code, from the Zip task class all the way up to the AbstractCopyTask class. I discovered that an copy task (like Zip) has two copy specs, a root one (rootspec), and a child one (mainspec). In the distribution plugin, calling the into method on the zip task that takes a path and a closure uses the path for the main spec, not the root spec (at least, that’s my understanding). So I tried this:
tasks.windowsDistTar.into(‘rootFolder’)
tasks.windowsDistZip.mainSpec.into(‘blop’)
I ended up with an archive that has the root folder called ‘rootFolder’, that contains a folder called ‘blop’. I thought it all made sense and maybe I didn’t have to change the ‘into’ of rootSpec and could just change the one on mainSpec (I want one root folder only, not a root folder and a subroot folder).
So I just did
tasks.windowsDistZip.mainSpec.into(‘rootFolder’) Unfortunately, this caused the root folder to be called ‘rootFolder’ (great) BUT it did contain a subfolder called ‘defaultRootFolder’, which I don’t want.
How can I get just one root folder in my archive, and specify its name?
Thanks in advance.
I am still looking into it, trying to understand how I can override the value for “into” that is being passed at task (dynamic) creation and also trying to understand why there can be both a root folder and a “subroot” folder in the archive. There must be a solution to this. I’m trying to stay away from messing with rootSpec and mainSpec as they look like internals and I’d really like to stick to public API if possible.