Is 'idea' plugin code executed when importing a gradle build in Intellij?

I’ve got a block of code in my build script that’s suppose to customise the generated ‘iml’ file. It’s something like below (not really my script but taken from Gradle documentation as an example):

idea.module.iml {
    whenMerged { module ->
        module.dependencies*.exported = true
    }
}

This block does not seem to be executed at all when the project is ‘imported’ into Intellij (e.g. import the project by selecting build.gradle). The resulting auto-generated ‘iml’ file does not contain the customisation expected. However, the customisation is done if the ‘iml’ file is generated by executing ‘gradle ideaModule’ task from the command line.

Basically we need to modify the order of library dependencies a bit with as little manual interventions as possbile from the developer and I thought the ‘idea’ plugin would provide me the ‘hook’ to do that during importing but nothing happened.

So my question is whether the build script of the ‘idea’ plugin really executed when ‘importing’ project in Intellij? If not, is that how it’s suppose to work or it might be a Intellij bug?

Thanks!

The properties on IdeaModule are exposed via the Tooling API (used by IntelliJ during import) so something like idea.module.name = 'foo' would be reflected. Manually modifying the XML however is only taken into affect when running the idea task. This simply isn’t exposed to IntelliJ.

Thanks for the reply! That makes more sense now.