Higher level question: Why is it always so hard to find all the properties that we can modify for a gradle plugin? (Remember how easy javadoc was - I feel like I am missing something in my doc navigation skills for gradle)
Detailed question:
I remember there was a property for the application plugin to change where the *.zip and *.tar file was generated. In this way, I could redirect all projects to output all zips to a single directory. I can’t seem to find it through these links
SPECIFICALLY, I just want to modify the directory of where the .zip distribution is put when building
nothing really there and I give up. This seems pretty common when trying to understand what options are available. Is there a better way of how people navigate this?
I feel your pain… Pulling all the threads together from the Gradle docs that you need to achieve a particular outcome is a skill in its own right.
The specific answer to your question is not in a property of the distribution plugin, but the destinationDirectory of the Zip task (I use Tar, but I assume that Zip works in the same way.)
The wrinkle is that you need a DirectoryProperty, not a File to set destinationDirectory. I do it something like this, where tarDestDir has been assigned a string containing the absolute path to the directory:
Actually I disagree regarding the docs, I always found the Gradle docs pretty good and extensive, but YMMV of course, as this is very subjective.
Why is it always so hard to find all the properties that we can modify for a gradle plugin?
Each plugin documentation page should state which properties you can configure.
And additionally if you use the Kotlin DSL and a proper IDE like IntelliJ, you also have amazing IDE support with auto-completion and so on and type-safe build scripts immediately, I can just everyone recommend using it.
I remember there was a property for the application plugin to change where the *.zip and *.tar file was generated.
Actually that is nor a property of the application plugin, neither of the distribution plugin. It is a property of the base plugin that is basically applied by all built-in plugins:
base {
distsDirectory.set(layout.buildDirectory.dir("myDistributionFolder"))
}
or as mentioned by @pkeller, you can also configure the single tasks, just NOT the way he was showing it which is majorly wrong. (see below)
The wrinkle is that you need a DirectoryProperty, not a File to set destinationDirectory
That is not true.
You can set a DirectoryProperty using a Directory, a Provider<Directory>, or a File.
Never change the configuration of a task - and especially its inputs and outputs - during its execution phase
If you want to set a DirectoryProperty from a File, there is no need for a Directory or DirectoryProperty, just use a File.
'$tarDestDir' in Groovy is literal and is not expanded, so new File('$tarDestDir') is a directory called literally $tarDestDir in the current working directory of the build execution which can also vary from run to run and might even be non-writable. Every build that depends on paths relative to the working directory should be considered flaky and broken.
If you actually have an absolute path, just do destinationDirectory.set(new File(theVariableHoldingTheAbsolutePath)), if you have a relative path, do something like destinationDirectory.set(layout.buildDirectory.dir("myDistributionFolder")) or similar.