Chapter 43. The Distribution Plugin

The distribution plugin is incubating (see Section C.1.2, “Incubating”).

The distribution plugin extends the language plugins with common distribution related tasks. It allows bundling a project including binaries, sources and documentation.

43.1. Usage

To use the distribution plugin, include in your build script:

Example 43.1. Using the distribution plugin

build.gradle

apply plugin: 'distribution'

To define the name for the distribution you have to set the baseName property as shown below

Example 43.2. Configure the distribution name

build.gradle

distributions {
    main {
        baseName = 'my-name'
    }
}

The plugin build a distribution for your project. You can run gradle distZip to create a ZIP containing the distribution. Given that the project name is myproject and version is 1.2, then running gradle customDistZip will produce a ZIP file called myproject-1.2.zip

43.2. Tasks

The Distribution plugin adds the following tasks to the project.

Table 43.1. Distribution plugin - tasks

Task name Depends on Type Description
distZip - Zip Creates a full distribution ZIP archive.
distTar - Tar Creates a full distribution TAR archive.
installDist - Sync Install distribution contents.

43.3. Configure distributions

The distribution plugin allow to configure distributions to include custom files and to change distribution baseName.

Example 43.3. Declare multiple distributions

build.gradle

apply plugin: 'distribution'

distributions {
    main {
        baseName = 'someName'
        contents {
            from { 'src/dist' }
        }
    }
}

43.4. Multiple distributions

The distribution plugin allow to generate multiple distributions.

Example 43.4. Declare multiple distributions

build.gradle

apply plugin: 'distribution'

version = '1.2'
distributions {
    custom {
        contents {
            from { 'src/dist' }
        }
    }
}

This will following tasks to the project : customDistZip, customDistTar, installcustomDist. Given that the project name is myproject, then running gradle customDistZip will produce a ZIP file called myproject-custom-1.2.zip and running customDistTar will produce myproject-custom-1.2.tar. Running installcustomDist will install distribution contents into buildDir/install/custom.

43.5. Extension properties

The distribution plugin add an extension to the project, which you can use to configure its behaviour. See Project.