Is there a way to refer to a task before it is defined

I am trying to add a dependency which is present in a zip file hosted in server.
I need to download the zip file and extract it and add a jar file from the extracted location as a dependency.
I am trying the following.

configurations {
testzip
}

dependencies {
testzip group:‘com.company’, name: ‘test’, version:‘1.0.0’, ext:‘tgz’

compile files({tasks.testTask.extractedJars})

}

task testTask(type: Sync) {
def extractDir = “tmpDeps”
ext.extractedJars = fileTree(extractDir) {
include “/dist/test.jar”
builtBy “testTask”
}
dependsOn configurations.testzip
from {
configurations.testzip.collect{tarTree(it)}
}
into extractDir
}

When I run the build I get this error
Could not get unknown property ‘testTask’ for task set.
I am not sure how to fix this issue.
I am looking at the documentation but could not figure out anything.
Please help with this issue.

Thanks

I think you could do this

configurations {
    tars
} 
dependencies {
    tars 'com.mycompany:test:1.0.0@tgz'
    compile files({tasks['unzip']}) 
} 
task unzip {
    inputs.files configurations.tars
    outputs.dir "$buildDir/unzip" 
    doLast {
        copy {
            from tarTree(configurations.tars.singleFile).matching {
                include "dist/test.jar" 
            } 
            into "$buildDir/unzip" 
        } 
    } 
} 

Hi Lance,

Thanks for you solution.
I tried this and I see that the jar file is being extracted to the intended location.
But when I run dependencies task I don’t see the jar file in the list of dependencies output.
Build fails with the error missing classes from the dependency jar.
Am I missing something? Is there any other way to pass on files list from a task to compile dependency.

Thanks
Sai

Perhaps try

outputs.file "$buildDir/unzip/dist/test.jar"

Instead of

outputs.dir "$buildDir/unzip"