Reputation: 13395
I've got two simple tasks
task initdb { println 'database' }
task profile(dependsOn: initdb) << { println 'profile' }
During runtime the result in console looks like this
When my tasks looks like this
task initdb { println 'database' }
task profile() << { println 'profile' }
the result in console is
How to skip initdb
task when it's not used in the task profile
in runtime? (without using -x
)
Upvotes: 0
Views: 1511
Reputation: 123910
The reason for this behavior is that initDb
isn't declared correctly. It's missing a <<
, and hence the println
statement gets run at configuration time rather than execution time. This also means that the statement always gets run. This doesn't mean that the task gets executed (in the second example it doesn't).
To avoid such mistakes, I recommend to use the more explicit and regular doLast
syntax in favor of <<
:
task profile {
// code in here is about *configuring* the task;
// it *always* gets run (unless `--configuration-on-demand` is used)
dependsOn initdb
doLast { // adds a so-called "task action"
// code in here is about *executing* the task;
// it only gets run if and when Gradle decides to execute the task
println "profile"
}
}
Upvotes: 3