# Chapter 44. The Distribution Plugin

The distribution plugin is currently incubating. Please be aware that the DSL and other configuration may change in later Gradle versions.

The distribution plugin facilitates building archives that serve as distributions of the project. Distribution archives typically contain then executable application and other supporting files, such as documentation.

## 44.1. Usage

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

Example 44.1. Using the distribution plugin

`build.gradle`

    apply plugin: 'distribution'

The plugin adds an extension named "`distributions`" of type `DistributionContainer` to the project. It also creates a single distribution in the distributions container extension named "`main`". If your build only produces one distribution you only need to configure this distribution (or use the defaults).

You can run "`gradle distZip`" to package the main distribution as a ZIP, or "`gradle distTar`" to create a GZip compressed TAR file. The files will be created at "``$buildDir`/distributions/`$project.name`-`$project.version`.`«ext»``".

You can run "`gradle installDist`" to assembles the distribution content, uncompressed, into "``$buildDir`/install/`main``".

## 44.2. Tasks

The Distribution plugin adds the following tasks to the project:

Table 44.1. Distribution plugin - tasks

Task name | Depends on | Type | Description
`distZip` | `-` | `Zip` | Creates a ZIP archive of the distribution contents
`distTar` | `-` | `Tar` | Creates a ZIP archive of the distribution contents
`installDist` | `-` | `Sync` | Assembles the distribution content and installs it on the current machine

For each extra distribution set you add to the project, the distribution plugin adds the following tasks:

Table 44.2. Multiple distributions - tasks

Task name | Depends on | Type | Description
``${distribution.name}`DistZip` | `-` | `Zip` | Creates a ZIP archive of the distribution contents
``${distribution.name}`DistTar` | `-` | `Tar` | Creates a TAR archive of the distribution contents
`install`${distribution.name.capitalize()}`Dist` | `-` | `Sync` | Assembles the distribution content and installs it on the current machine

Example 44.2. Adding extra distributions

`build.gradle`

    apply plugin: 'distribution'

    version = '1.2'
    distributions {
        custom {}
    }

This will add following tasks to the project:

- customDistZip
- customDistTar
- installCustomDist

Given that the project name is "`myproject`" and version "`1.2`", running "`gradle customDistZip`" will produce a ZIP file named "`myproject-custom-1.2.zip`".

Running "`gradle installCustomDist`" will install the distribution contents into "``$buildDir`/install/custom`".

## 44.3. Distribution contents

All of the files in the "`src/`$distribution.name`/dist`" directory will automatically be included in the distribution. You can add additional files by configuring the `Distribution` object that is part of the container.

Example 44.3. Configuring the main distribution

`build.gradle`

    apply plugin: 'distribution'

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

In the above example, the content of the "`src/readme`" directory will be included in the distribution (along with the files in the "`src/dist/main`" directory which are added by default).

The "`baseName`" property has also been changed. This will cause the distribution archives to be created with a different name.