Why are my custom tasks being executed when I start up the Gradle GUI?


(Todd Gerspacher) #1

At the moment this isn’t really an issue for me, but it is kind of unexpected. Why are my custom tasks being executed when I start up the Gradle GUI? None of the built-in tasks get executed when the GUI starts up. I have to manually start them. Shouldn’t custom tasks perform the same way? For example, if the following is my build script.

task fooBar {
 println "executing fooBar task"
}

Then when I start up the Gradle GUI it will automatically execute the fooBar task.


(Radim Kubacki) #2

This is a common mistake: your block with println is used to configure the task and means that the message is printed during configuration phase. Use doLast {} in your configuration or a shorcut definition like in http://www.gradle.org/docs/current/userguide/tutorial_using_tasks.html#N10222

task fooBar << {
  println 'hello'
}

(Perryn Fowler) #3

that println wont happen at execution, it happens at configuration

It is important to understand the difference between the configuration phase and the execution phase. Take a look at Chapter 15 and Chapter 54 of the user guide

http://www.gradle.org/docs/current/userguide/build_lifecycle.html http://www.gradle.org/docs/current/userguide/more_about_tasks.html

if you want to print something at execution time, try:

task fooBar << {
    println "executing fooBar task"
}

(Todd Gerspacher) #4

Ah, okay. Thanks.