Idea plugin: iml.withXml not executed if project is imported from gradle

Hi All,

Why idea.iml.withXml is not invoked when a gradle project is imported into idea? But if I run

 gradle idea

it is invoked as expected.

This question was already asked[1], but there is no solution.


Thanks in advance,
Rafael Torres

Hi @rdtorres.

Do you mean that opening build.gradle with IntelliJ IDEA doesn’t generate an iml file as you wish?
If so, I think this problem is not Gradle’s, but IntelliJ IDEA’s. It seems that IntelliJ IDEA generates an iml file by itself and doesn’t see idea{} block.

My solution is…

  1. Run idea task.
  2. Import project via the ipr file generated by Gradle.
  3. Ignore all suggestions on Gradle from IntelliJ IDEA.


  1. Import Gradle project with IntelliJ IDEA.
  2. Run idea task and override iml file.
  3. Reopen the project prompted by IntelliJ IDEA
  4. Ignore all suggestions on Gradle from IntelliJ IDEA after reopening project.

Hi @Shinya_Mochida,

The idea{} block is executed, but not the inner withXml block. I’m inclined to believe this is an IntelliJ issue.

Thanks for the suggested solutions, but in my case I’m using android studio and our build.gradle files change often. So it is very convenient to update the source tree and “automagicaly” recreate .iml files when it changes instead of manually recreate it.

Rafael Torres

Hi @rdtorres, I am having the same problem as you. I am trying to modify one module’s .iml file and the withXml closure does not execute. Did you ever figure out why?

Here’s a simple version of my use case:

idea.module { += [configurations.myCustomConfiguration] //this works and adds directories to module deps

  iml {
    withXml {
    //append some node here... but never executes

I am using IJ 2017.2.5 (Build #IC-172.4343.14) and Gradle 4.3-rc-1.