Lazy dependency evaluation, how?


I observe that running ./gradlew tasks appears to evaluate the closures in copy task “from” clauses. For example, this code:

dependencies {
    myConfig computeMyDependency()

task copyMyDependencyFile(type: Copy) {
    from { configurations.myConfig
               .grep {"zip") }
               .collect() { zipTree it }
    into targetDir

will not only evaluate computeMyDepency() but also try to resolve and download it.

How do I prevent ./gradlew tasks from doing that?

What does computeMyDependency() do?

gradlew tasks has to determine the inputs for all tasks to be able to show dependencies between tasks. That’s what’s triggering the resolution.

Would it be happy with just the formal notation of the dependency? Why does it have to attempt to download the actual dependency?

computeMyDependency() figures out which version of an artifact to get from the artifact repository, and bails if the required artifact is not present. It wouldn’t bail when building in our CI system, because it guarantees that the artifact is present, but for developer it can happen.

Hence my current workaround to resolve computeMyDependency to files('.') when it isn’t present… which is an awful hack IMHO.

Maybe it would make more sense to only consider dependencies listed in DependsOn, or only consider task and project dependencies?

As it currently is, you could be downloading gigabytes of data just to throw it out as you realize it is not useful to display task dependencies.

So I guess for the meantime, I’d request a feature for defining a “null” dependency, which doesn’t affect operations like gradle tasks, but will cause copy tasks or similar operations which do require an input to fail.