Gradle Distribution Plugin: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 35: Line 35:
File distributionFile = new File(project.buildDir, "distributions"), distributionBaseName + ".zip")
File distributionFile = new File(project.buildDir, "distributions"), distributionBaseName + ".zip")
</syntaxhighlight>
</syntaxhighlight>
<font color=darkgray>Better way than this?</font>


=Concepts=
=Concepts=

Revision as of 08:19, 24 February 2019

External

Internal

Overview

The Distribution plugin builds archives that serve as distributions of the project. They typically contain the executable application and other supporting files, such as the documentation. The Distribution plugin is part of the Application plugin flow.

The plugin adds an extension named "distributions" of type DistributionContainer. The extension is available though the ExtensionContainer:

...
ExtensionContainer ec = project.extensions;
DistributionContainer dc = ec.getByName("distributions");
Distribution d = dc.getByName("main");
...

It also creates a single distribution in the distributions container, named "main". Multiple distributions can be configured.

The distribution files are created in $buildDir/distributions/$project.name-$project.version.<ext>.

This is how the distribution file can be defined dynamically in the build.gradle file:

ExtensionContainer ec = project.extensions;
DistributionContainer dc = ec.getByName("distributions");
Distribution d = dc.getByName("main");
String distributionBaseName = d.baseName;
File distributionFile = new File(project.buildDir, "distributions"), distributionBaseName + ".zip")

Better way than this?

Concepts

Distribution

Distribution

Building Custom Files with the Distribution

All files in the ./src/<distribution-name>/dist directory will be automatically included in the distribution. There is always a default "main" distribution.

Additional files can be added by configuring the Distribution object:

apply plugin: 'distribution'

...

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

In this example, the content of the "src/readme" directory will be included in the distribution along with the files in "src/main/dist". Changing the "baseName"will cause the distribution archives to be created under a different name.

Multiple Distributions

See "Adding extra distributions" in documentation.