The XML accessed from whenMerged is always empty, is it?

Supposedly whenMerged is called after the Gradle IDEA plugin has merged Gradle’s dependencies in. However, what I see is that this:

whenMerged { module ->
  println module.xml.component.orderEntry.size()
}

Prints 0 for every single module.

So I’d say that whenMerged is actually called before the merge occurs, and the docs are a little misleading. Either that, or the xml method is not working correctly.

withXml is definitely called after the merge, and using that seems to be an acceptable workaround.

Another gripe I have in this area is that if you trigger an exception from your whenMerged block, in addition to causing the build to fail, Gradle will also corrupt your IML file as a free service so that the next build fails as well. All updates to any files in the project should be performed atomically so that this can’t happen.