Lib files cache problem with android compile task

I’ve got a problem dragging me for days, the problem is:
in one module dependencies setup

dependencies {
    provided fileTree(dir: 'libs', include: ['*.jar'])
}

If all the required jars are in the folder when gradle starts, compileReleaseJava runs fine.
But if the libs folder is initially empty, and I create a copy task which runs before compileReleaseJava to pump all the jars into the libs folder. The compileReleaseJava fails due to no dependencies found

I’ve tried with the following, not working neighter

provided files('libs') {
      builtBy 'copyLibs'
    }.getAsFileTree().matching{
        include '**/*.jar'
    }

Look at AbstactCompile.java, some magic happnens with

@InputFiles
public FileCollection getClasspath() {
    return classpath;
}

classpath was a file collections of jars if initially the libs are non empty. but I have no idea where is this coming from.

any ideas? any documents systematically tells the big picture of the gradle on execution flow, task creation, task input, listeners, caching mechanism etc

update with info:
gradle 2.4, android plugin 1.2.3

so, it seems the file collection value evaluates at the configuration phase, and after that, it could not change.

You have to investigate when your ‘provided’ configuration gets resolved for the first time.
Use a “beforeResolve” method call on this configuration with a “println” or a “throw GradleException” inside its closure parameter, in order to know when this happens.

I guess it happens before the ‘compileReleaseJava’ task, and that’s why your attempt fails.
Before using the Eclipse plug-in to configure my classpath, I was using a similar technique and it was working fine.