Could not determine the dependencies of task ':B:extractDeps'.
> Cannot expand ZIP '/home/jenkins/workspace/A/build/distributions/A-13.0.0-SNAPSHOT-template.zip' as it does not exist.
But of cause it does not exist as it hasn’t been built yet.
If I start build on A manually, everything is fine. And If I then start the build again, all is working too, because now the missing artifact is created. But it should also work after a clean.
Gradle does not know that the extractDeps task depends on the template configuration and therefore cannot infer the required task dependencies. The following should do two things for you; 1. Let Gradle know what the input files are for up-to-date checking. 2. The required task dependencies will be inferred.
Thanks, but this does not change a thing.
Maybe the problem is somehow that gradle checks for the zip already in the configuration phase, but it is first created in the execution phase. Is it somehow possible to postpone the check?
I tried to squeeze in DoLasts every now and then, but best I could get was a “NO-SOURCE” for extractDeps or syntax errors. And honoestly I thought using a closure in the from statement should be enough to get to the execution phase.
There was a similar issue in the buildTemplate task and this was solved by using the closure in the from statement.
OK, I see what you’re running into. extractDeps is configured using from( Closure ). This closure will be called multiple times during Gradle’s lifecycle (I’m seeing 5 calls). One of the calls happens right after the projects are configured and before the task graph is generated. This is part of Gradle gathering all the task inputs in order to discover any inferred task dependencies. Since the dependent task hasn’t run yet zipTree fails.
The closure will need to handle the case where the file does not exist yet and calling inputs.files will allow Gradle to discover the required task dependencies.
task extractDeps( type: Copy ) {
inputs.files configurations.template
from {
configurations.template.collect {
if( it.exists() ) {
zipTree( it ).matching{ include '**/*.xml' }.files
}
}
}
into( 'deps' )
}
Here’s an alternative way of implementing the extractDeps task that avoids having a closure called so many times:
task extractDeps {
ext {
inFiles = configurations.template
outDir = file( 'deps' )
}
inputs.files( inFiles )
outputs.dir( outDir )
doLast {
project.copy {
inFiles.each {
// No longer need to check if the file exists because we're
// guaranteed to be in task execution and this task's dependencies
// will have been executed.
from( zipTree( it ).matching{ include '**/*.xml' } )
}
into( outDir )
}
}
}