Chapter 55. The Java Library Distribution Plugin

Table of Contents

55.1. Usage
55.2. Tasks
55.3. Including other resources in the distribution

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

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.

55.1. Usage

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

Example 55.1. Using the Java library distribution plugin


apply plugin: 'java-library-distribution'

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

Example 55.2. Configure the distribution name


distributions {
        baseName = 'my-name'

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

55.2. Tasks

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

Table 55.1. Java library distribution plugin - tasks

Task name Depends on Type Description




Creates a full distribution ZIP archive including runtime libraries.

55.3. 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 them to the content of the distribution.

Example 55.3. Include files in the distribution


distributions {
    main {
        baseName = 'my-name'
        contents {
            from { 'src/dist' }