Gradle Distribution Plugin: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=External= =Internal= * Gradle Concepts * Gradle Application Plugin =Overview=")
 
 
(19 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
=External=
* https://docs.gradle.org/4.7/userguide/distribution_plugin.html


=Internal=
=Internal=


* [[Gradle_Concepts#Artifact|Gradle Concepts]]
* [[Gradle_Artifacts#The_Distribution_Plugin|Gradle Artifacts]]
* [[Gradle_Application_Plugin#Overview|Gradle Application Plugin]]
* [[Gradle_Application_Plugin#Overview|Gradle Application Plugin]]


=Overview=
=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 [[Gradle_Application_Plugin#Overview|Application plugin]] flow.
The plugin adds an [[Gradle Extensions#Overview|extension]] named "distributions" of type [https://docs.gradle.org/4.7/dsl/org.gradle.api.distribution.DistributionContainer.html DistributionContainer]. The extension is available though the ExtensionContainer:
<syntaxhighlight lang='groovy'>
...
ExtensionContainer ec = project.extensions;
DistributionContainer dc = ec.getByName("distributions");
Distribution d = dc.getByName("main");
...
</syntaxhighlight>
It also creates a single distribution in the distributions container, named "main". [[#Multiple_Distributions|Multiple distributions]] can be configured.
The distribution files are created in <tt>$buildDir/distributions/$project.name-$project.version.<''ext''>.</tt>
This is how the distribution file can be defined dynamically in the build.gradle file:
<syntaxhighlight lang='groovy'>
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")
</syntaxhighlight>
<font color=darkgray>Is there a better way than this, that does not require so much coding in build.gradle?</font>
=Concepts=
==Distribution==
A distribution is an atomic artifact (ZIP or TAR) built by this plugin.
{{External|[https://docs.gradle.org/4.7/javadoc/org/gradle/api/distribution/Distribution.html 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 [https://docs.gradle.org/4.7/javadoc/org/gradle/api/distribution/Distribution.html Distribution] object:
<syntaxhighlight lang='groovy'>
apply plugin: 'distribution'
...
distributions {
    main {
        baseName = 'someName'
        contents {
            from { 'src/readme' }
        }
    }
}
</syntaxhighlight>
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=
<font color=darkgray>See "Adding extra distributions" in documentation</font>.

Latest revision as of 18:45, 23 April 2021

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")

Is there a better way than this, that does not require so much coding in build.gradle?

Concepts

Distribution

A distribution is an atomic artifact (ZIP or TAR) built by this plugin.

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.