Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a gradle task before any distributions are built

Tags:

gradle

I've got a gradle build with source and javadoc jars and I'd like these tasks to be executed before distZip and distTar, is there a dependency that captures both of those for use with shouldRunAfter.

Right now I've got:

task javadocJar(type: Jar) {
    classifier 'javadoc'
    from javadoc
}

task sourcesJar(type: Jar) {
    classifier 'sources'
    from sourceSets.main.allSource
}

tasks.distZip.shouldRunAfter tasks.javadocJar
tasks.distTar.shouldRunAfter tasks.javadocJar
tasks.distZip.shouldRunAfter tasks.sourcesJar
tasks.distTar.shouldRunAfter tasks.sourcesJar

I'd like to condense down those four shouldRunAfter to two which captures both distZip and distTar.

like image 493
Daniel Skogquist Åborg Avatar asked Jan 21 '16 17:01

Daniel Skogquist Åborg


People also ask

Does Gradle build run all tasks?

You can execute multiple tasks from a single build file. Gradle can handle the build file using gradle command. This command will compile each task in such an order that they are listed and execute each task along with the dependencies using different options.


1 Answers

You can use groovy syntax to make this shorter

[distZip, distTar]*.shouldRunAfter javadocJar, sourcesJar

Probably you also want dependsOn instead of shouldRunAfter so that the jars are built whenever one of the dist tasks is enabled.

like image 65
Henry Avatar answered Sep 20 '22 13:09

Henry