Distribution plugin : generate only a tar (or avoid generate zip)

Hi All,

I am using the distribution plugin, it works file and generate the archive with the right content. My only problem is that I want to generate only a tar when I run the install or assemble tasks instead of the 2 distributions. Is there a way to configure the plugin in that way ?

Thanks,

Will

Canā€™t you just disable it? See https://docs.gradle.org/current/userguide/more_about_tasks.html#N11326

so you would add this to your build.gradle:
tasks.distZip.enabled = false

I have the same problem, disabling the task suppresses the generation of the zip, however artifactoryPublish still wants to upload the missing archive and fails.

How does one properly disable the tar/zip archive?

I use Gradle 3.3 if that matters.

1 Like

I canā€™t seem to get this to work. I tried both of the following in my build.gradle; one at a time. But I always end up with both zip and tar archives. I only want the zip archive but canā€™t seem to get the distTar task to stop running.

tasks.distZip.enabled = false
tasks.distTar.enabled = false

I must be doing something wrong. I tried Gradle versions 4.5.1 to 4.3 but same result every time. Why canā€™t I disable one of the archive tasks?

I realized why tar files were still being generated. After applying distribution plugin, I defined several custom distribution name. For example:

distributions {
  dist1 {
    ...
  }
  dist2 {
    ...
  }
  dist3 {
    ...
  }
}

Each of those distributions are assigned a task to produce a tar file and a zip file. So, in order to skip tar file OR zip file creation, they have to be specifically disabled. A good way of doing that would be to use the task graph. For example:

gradle.taskGraph.whenReady { graph ->
    graph.allTasks.findAll { it.name ==~ /.+DistTar/ }*.enabled = false
}

While this works, itā€™d be really nice if the Distribution plugin provides a configuration for this. It could be something like this:

distribution {
  disableDistZip = true | false
  disableDistTar = true | false

  dist1 { ... }
  dist2 { ... }
}

It seems a slightly odd default to generate BOTH the tar and the zip, I too ended up adding the opimization to only generate the one we actually used.

I canā€™t think itā€™s very often that both files are needed, itā€™s a pity the default isnā€™t either one or the other, with the option to switch to output both.

Unless you have an inconsistent need for tar files in some places, but just not distributions, it would be more conventional to just disable the Tar tasks:

tasks.withType(Tar) {
    enabled = false
}

The plugin was designed to easily create distributions of an application for end users. Application downloads of this type often offer ZIP for Windows and a TAR for the Linux/Unix-like platforms, even if they have the same contents.

Thatā€™s a nicer approach thank going through the task graph. Thanks James for the suggestion.

If this plugin was designed for distributing ā€œan applicationā€, then I think it makes sense but I havenā€™t actually seen any example that demonstrate this. All the example/usage of this plugin I have seen so far simply shows creating an archive with some files that are automatically picked up from a path as part of the pluginā€™s convention (i.e. src/$distribution.name/dist) or add files from custom path. The User Guide of this plugin doesnā€™t really have a lot of examples.

https://docs.gradle.org/current/userguide/distribution_plugin.html

Do you happen to have an example on how this plugin is supposed to be used? For example, build and application and bundle it using this plugin for distribution.

I wonder if this (disabling tar and zip) is worth documenting in the application plugin. We use the application plugin in our project solely to create a command-line tool usable by developers of our project, not to actually create a distribution, so the default of adding the slow distZip and distTar tasks to ā€˜build -> assembleā€™ isnā€™t great (and neither is the default of not having installDist be a dependency of ā€˜buildā€™). It might be nice to have a section in the docs that says something like: if youā€™re using the application plugin just to create a tool to use in dev, not to distribution, youā€™ll want to add

tasks.distZip.enabled = false
tasks.distTar.enabled = false
build.dependsOn installDist

Unless Iā€™m missing something and thereā€™s another mechanism recommended for this use case!

1 Like

I absolutely agree. Iā€™ve had some use for this in multiple projects in the last 6 months and this is the first time Iā€™ve found a nice gradley solution. Before Iā€™ve used solutions where I scripted unpacking of the tar as part of the build because I couldnā€™t find these documented anywhere.