Calling configurations.*.each in a Gradle task makes my build fail


This is weird.

I have a Gradle multiplatform project. Among my other modules, I have client (for the Javascript client) and konan (for the native code portion).

I want to collect the various libraries in the Javascript client for deployment, so I add this to client's build.gradle:

task populateProdNodeModules(type: Copy) {
    configurations.compile.each {
        from zipTree(it.absolutePath).matching { include '*.js' }

    into "$libDir/prod"

Note, this is not depended on by anything yet — the task never runs. But konan's build now fails with massive spewing of ‘unresolved reference’ errors. Note that the build file I’ve just edited is in client and has nothing whatsoever to do with konan. The only thing they have in common is that they both depend on the same shared module.

Backing out changes shows that this is sufficient to make the build fail:

task populateProdNodeModules(type: Copy) {
    configurations.compile.each {}

Commenting out the configurations.runtime.each line makes everything happy; leaving it uncommented makes the build fail. Using runtime or testCompile causes the same failure.

It looks like the reason for the failure is that Gradle has forgotten about all the shared module which konan depends on, so it tries to compile the program with all the business logic missing, with predictable results. But I have no idea why simply calling configurations.compile.each might cause this to happen.

What on earth is going on?