Lazy dependency resolution - completely conditional configuration/dependency?


I have a task which gets a big zip dependency and extracts it to some directory…

configurations {



dependencies {

bigzip “org.example.assets:bigzip:${bigZipVersion}@zip


task unpackBigZip(type: Copy, dependsOn: configurations.bigzip) {

ext.targetOutputDir = new File("$buildDir/unpack/bigzip")

outputs.dir targetOutputDir

from {

configurations.bigzip.collect { zipTree(it) }


into targetOutputDir


As this is only needed occasionally I wanted to make it conditional:

unpackBigZip.onlyIf { project.hasProperty(‘useBigZip’) }

The problem I have is that even the task is not executed (thanks to the “onlyIf” statement), the dependency is still downloaded by gradle…

How can I make it completely conditional? Any hints?

Thank you in advance, Marian

One way would be to wrap a conditional around the bigzip dependency declaration or all of it. It might be cleaner to just pull everything bigzip-related out into a secondary script and then only apply it if your conditional is met:

if (project.hasProperty('useBigZip')) {
  apply from: 'bigzip.gradle'

Why Gradle downloads artefacts before they are really requested? In this case, to download large file before actual task execution seems to be a bug.