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. To build both types of archives just run gradle assembleDist
.
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 35.1. Distribution plugin - tasks
Task name | Depends on | Type | Description |
distZip
|
-
|
Zip
|
Creates a ZIP archive of the distribution contents |
distTar
|
-
|
Tar
|
Creates a TAR archive of the distribution contents |
assembleDist
|
distTar , distZip
|
Task
|
Creates ZIP and TAR archives with 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 35.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 |
assemble
|
,
|
Task
|
Assembles all distribution archives |
install
|
-
|
Sync
|
Assembles the distribution content and installs it on the current machine |
Example 35.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 35.3. Configuring the main distribution
build.gradle
apply plugin: 'distribution' distributions { main { baseName = 'someName' contents { from { 'src/readme' } } } } apply plugin:'maven' uploadArchives { repositories { mavenDeployer { repository(url: "file://some/repo") } } }
In the example above, the content of the “src/readme
” directory will be included in the distribution
(along with the files in the “src/main/dist
” 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.
The distribution plugin adds the distribution archives as candidate for default publishing artifacts.
With the maven
plugin applied the distribution zip file will be published when running uploadArchives
if no other default artifact is configured
Example 35.4. publish main distribution
build.gradle
apply plugin:'maven' uploadArchives { repositories { mavenDeployer { repository(url: "file://some/repo") } } }