Dependency resolution when running 'gradle tasks'?

I have a question on lazy dependency resolution.

It seems to be working for me (using gradle 2.3) where my dependency only gets resolved if I run the task that depends on it.

The exception, however, is if I run ‘gradle tasks’. I’m surprised to discover it does attempt to to pull down my dependency. It was surprising to me since I was on a slow VPN connection and my zip dependency is large.

Why does ‘gradle tasks’ require dependencies to be resolved and is there a way to avoid it.

Here is a example of my code:

configurations {
 zip
}
  dependencies {
 zip "path.to.big:zipfile:1.0-SNAPSHOT@zip"
}
  task explodeApp(type: Copy, dependsOn: configurations.zip) {
      from { zipTree(configurations.zip.singleFile) }
    into "${appDir}"
}
  // running hello task does not download zip file
task hello << {
 print "hello"
}

Here is the output:

% gradle hello
:hello
hello
BUILD SUCCESSFUL
  ----------
  % gradle tasks
:tasks
  ------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
  Download http://myrepo//path/to/big/zipfile/1.0-SNAPSHOT/zipfile-1.0-20150306.195305-1.zip
[... waing long time on slow connection]

Thanks.

I think I asked this before and the answer was that the ‘tasks’ task is “special”.

You can prevent ‘tasks’ from resolving your dependencies by wrapping the ‘from … configurations.zip.singleFile’ line inside a doFirst or doLast block.

You typically don’t want to do that though, since doing configuration during the execution phase will break up to date checking.

correct, so I mitigate that by putting a “inputs.files configurations.zip” line in the task configuration.