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 the executable application and other supporting files, such as documentation.
To use the distribution plugin, include the following in your build script:
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 TAR file.
The files will be created at “
”.
$buildDir
/distributions/$project.name
-$project.version
.«ext»
You can run “gradle installDist
” to assemble the uncompressed distribution into “
”.
$buildDir
/install/main
The Distribution plugin adds the following tasks to the project:
Table 44.1. Distribution plugin - tasks
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 |
|
-
|
Zip
|
Creates a ZIP archive of the distribution contents |
|
-
|
Tar
|
Creates a TAR archive of the distribution contents |
install
|
-
|
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:
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
All of the files in the “src/
” directory will automatically be included in the distribution.
You can add additional files by configuring the $distribution.name
/distDistribution
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 example above, 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.