Chapter 43. The Java Library Distribution Plugin

The Java library distribution plugin is incubating and should not be considered stable.

The Java library distribution plugin adds support for building a distribution ZIP for a Java library. The distribution contains the JAR file for the library and its dependencies.

43.1. Usage

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

Example 43.1. Using the java library distribution plugin

build.gradle

apply plugin: 'java-library-distribution'

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

Example 43.2. Configure the distribution name

build.gradle

distribution {
    name = 'my-name'
}

The plugin build a distribution for your library. The distribution will package up the runtime dependencies of the library All files stored in src/dist will be added to the root of the archive distribution. You can run gradle distZip to create a ZIP containing the distribution.

43.2. Tasks

The Java library distribution plugin adds the following tasks to the project.

Table 43.1. Java library distribution plugin - tasks

Task name Depends on Type Description
distZip jar Zip Creates a full distribution ZIP archive including runtime libraries.

43.3. Extension properties

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

43.4. Including other resources in the distribution

All of the files from the src/dist directory are copied. To include any static files in the distribution, simply arrange them in the src/dist directory, or add it to the task.

Example 43.3. Include files in the distribution

build.gradle

distZip {
    from('oneFile') //Copy to the root of the distribution
    from('secondFile') {
        into('dist') // Copy to the dist directory
    }
}