Build UP-TO-DATE even with --rerun-tasks

Hi everybody,

I have a simple task

task unpackJetty(type:Copy) << {
    from zipTree('../../../vendors/')
    into '${distsDir}'
    exclude 'javadoc'
    exclude 'examples'
    exclude 'contexts/test.xml'

It never runs, never actually unpacks the zip file because it claims it is UP-TO-DATE

gradle --rerun-tasks unpackjetty
:myproject:unpackJetty UP-TO-DATE
  Total time: 0.995 secs

What’s going on? Thanks, Andras

The << needs to go. Always use ‘doLast’ instead of << , and this mistake won’t happen again.

Thanks Peter.

I was vaguely aware that << does something like doLast (now I know it’s just an alias to doLast), but it is still a bit confusing, as I would expect the doLast closure to be executed when the task is executed. I guess I still don’t fully understand what’s a “task action” and what should go to a “closure configuration”.

Can you please point me to a part of the documentation that makes this clear?

Thanks, Andras

Each task has a list of task actions. Executing the task means executing all its actions, from first to last. Tasks that specify a type such as ‘Copy’ already have one task action.

‘doLast’ will add another task action after the ‘Copy’ task’s main task action. In other words, your code is configuring the task after it has done its work. Even ‘doFirst’ wouldn’t have worked. This would come before the main task action, but after the task has determined that there is nothing to do (because no ‘from’ has been configured at that point).

Tasks need to be configured in the configuration phase, not in a task action (execution phase).

Thanks Peter, it makes sense now.