Gradle 8.12, using Groovy syntax.
I want to include the distribution
plugin in my build but I don’t want its tasks automatically placed in the build
dependency tree. In other words, I want to “opt-in” to running distZip
only when needed, not whenever build
task is run.
Right now, if I run gradlew build
, distZip
is included. When I want to use distZip
I want to explicitly request it (ie, with gradlew distZip
).
I do not want to totally disable distZip
, just make it an explicit choice.
Actually, the best would be to not use build
then.
build
depends on assemble
.
The distribution-base
plugin makes the assemble
task depend on the two archive tasks.
You can try to manipulate the assemble
dependencies, but usually this is not really a good or recommended idea.
Has it always worked this way, the Distribution Plugin (Distribution Base Plugin for 8.13+) adds the distZip
and distTar
outputs as project artifacts, and then assemble
builds all project artifacts (hence an implicit dependency between those tasks)?
I ask because the docs don’t really imply that relationship as I read them. They make it seem like assembleDist
is there for that purpose:
You can run
gradle distZip
to package the main distribution as a ZIP, orgradle distTar
to create a TAR file. To build both types of archives just rungradle assembleDist
.
assembleDist
— Task
Depends on:distTar
,distZip
Creates ZIP and TAR archives of the distribution contents.
I don’t see any mention of assemble
also doing so, and one has to wonder why assembleDist
is there if it does.
Has it always worked this way
Not always, but almost.
Commit 2ad16feb97e added the first distribution plugin version to Gradle 1.5.
And commits fb7460ae60f and 21c2bd25667 changed it in Gradle 2.3, so that there is an assembleXXXDist
task and that assemble
also builds those artifacts as they are most likely the end-result of a project and thus what assemble
should assemble build-wide.
I ask because the docs don’t really imply that relationship as I read them.
Could well be that it is not documented
They make it seem like
assembleDist
is there for that purpose
and one has to wonder whyassembleDist
is there if it does.
Not for that purpose and one does not have to wonder, one just have to ask.
assemble
assembles all artifacts of a project.
If a project for example builds a jar, a “main” distribution and a “secondary” distribution,
assemble
would build the jar
, the distZip
, the distTar
, the secondaryDistZip
, and the secondaryDistTar
.
assembleDist
just builds the distZip
, and the distTar
.
assembleSecondaryDist
just builds the secondaryDistZip
, and the secondaryDistTar
.
Thank you for the background. Good to know.
I filed an issue to request the addition to the documentation: Clarify that applying the Distribution Plugin creates a dependency between `assemble` and the distribution ZIP and TAR · Issue #32757 · gradle/gradle · GitHub.