How to Trigger Each Option
Option 1: Using the distribution Plugin
Applying id 'distribution' (or id 'application') automatically hooks tasks into your project lifecycle.
- Triggering explicitly:
-
./gradlew distTar(generates only the.tar/.tar.gz) -
./gradlew distZip(generates only the.zip) ./gradlew assembleDist(generates both zip and tar)Does
./gradlew buildcreate it by default?Yes, indirectly.
./gradlew buildtriggersassemble, which depends onassembleDist. This will automatically generate both a.zipand a.tarunderbuild/distributions/.Note: If you only want a TAR and want to disable the ZIP output during standard builds, you can add this to your
build.gradle:
tasks.named('distZip') { enabled = false }
Option 2: Standalone `tasks.register('buildAppTar', Tar)`
Because this is a custom-registered task, Gradle treats it as an opt-in task.
- Triggering explicitly:
./gradlew buildAppTarDoes
./gradlew buildcreate it by default?No. Custom tasks do not run during standard
./gradlew buildexecution unless you explicitly wire them into the build lifecycle:
// Wire it so ./gradlew build or ./gradlew assemble triggers it
tasks.named('assemble') {
dependsOn tasks.named('buildAppTar')
}
Which Option Should You Choose?
| Feature / Aspect | Option 1: distribution Plugin |
Option 2: Standalone Tar Task |
|---|---|---|
| Setup Complexity | Very Low (Idiomatic Gradle) | Low to Medium |
| Convention Support | Auto-includes ./src/main/dist content |
You must manually define every path |
| Publishing Integration | Built-in integration with maven-publish (components.java or distTar artifact) |
Requires manually attaching the output file to publishing
|
| Granular Control | Opinionated defaults | Full control over compression, permissions, and paths |
Recommendation
-
Choose Option 1 (
distributionplugin) if your project is a standard Java/Kotlin application or microservice. It is the Gradle standard, simplifies publishing configurations, and handles file permission metadata (0755for executables vs.0644for configs) out of the box. -
Choose Option 2 (Custom
Tartask) if you have strict, non-standard directory packaging requirements that conflict with Gradle's conventions, or if you want absolute control over when and how the archive is assembled.
For a walkthrough on creating zip/tar archives and managing tasks, see the Gradle Distribution Plugin tutorial.
Top comments (0)