How bind my task to specific stage of Gradle build

(aleksg) #1

I need bind my task ;‘cleanIgm’ to stage clean whish I see in list of stages of Java plugin.
I write like
task cleanAll(type: Delete) {
def tree = fileTree("$rootDir")
tree.include '**/*.jar’
tree.each { it.delete() }

When I run gradle clean this task shoul be run, correct?
How it works?
Stage clean of Java plugin bound to Delete task? How they connected each other?


(Dimitar Dimitrov) #2

Stages are a maven concept. In gradle you have a graph of tasks, so you can just call ‘taskBeforeWhichToCallMe.dependsOn(myCustomTask)’.

(aleksg) #3

Thanks. It’s diffiсult to me switching to Gradle from Maven.
If I write my own task which extends embedded task:

task fatJar(type: Jar) {
baseName = + '-all’
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar

it’ll be run on Jar stage automatically or not? Or I have to instruct Gradle to see and run my task somewhere inside other embedded tasks - like it’s being done in Ant?

(Jean-Baptiste Nizet) #4

Again, there is no Jar stage. Stages are a Maven concept. If you want it to run automatically when, for example, the assemble task (which is added to the build by the java plugin) is run, then use

assemble.dependsOn fatJar

Otherwise, you’ve just added a task to the build, which will only be invoked when executing gradle fatJar

(aleksg) #5

Thanks for explanation