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

**URL:** <https://discuss.gradle.org/t/idea-plugin-iml-withxml-not-executed-if-project-is-imported-from-gradle/11390>\
**Category:** Help/Discuss\
**Tags:** plugins\
**Created:** [August 28, 2015, 10:00pm UTC](https://discuss.gradle.org/t/idea-plugin-iml-withxml-not-executed-if-project-is-imported-from-gradle/11390 "2015-08-28T22:00:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rdtorres](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rdtorres/32/2851_2.png) [@rdtorres](https://discuss.gradle.org/u/rdtorres)\
**Post date:** [August 28, 2015, 10:00pm UTC](https://discuss.gradle.org/t/idea-plugin-iml-withxml-not-executed-if-project-is-imported-from-gradle/11390/1 "2015-08-28T22:00:05Z")

</div>

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.

[1]:

> [@Idea plugin: iml.withXml not applied if project imported from gradle](https://discuss.gradle.org/t/idea-plugin-iml-withxml-not-applied-if-project-imported-from-gradle/5835):
>
> I defined a build.gradle file with contents similar to that described in [http://forums.gradle.org/gradle/topics/org\_gradle\_plugins\_ide\_idea\_model\_module\_destroys\_content](http://forums.gradle.org/gradle/topics/org_gradle_plugins_ide_idea_model_module_destroys_content) I can see the expected changes to the .iml file if I run gradle idea However, if I import the project into IntelliJ from the gradle file, I do not see these changes. When importing, I do see the effects of changes to idea.module.sourceDirs, so I know my build.gradle file is being processed in some way. Is there a way I can g…

Thanks in advance,  
Rafael Torres

---

<div class="post-metadata">

**Author:** ![Shinya\_Mochida](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/shinya_mochida/32/2393_2.png) [@Shinya\_Mochida](https://discuss.gradle.org/u/Shinya_Mochida)\
**Post date:** [August 29, 2015, 6:19am UTC](https://discuss.gradle.org/t/idea-plugin-iml-withxml-not-executed-if-project-is-imported-from-gradle/11390/2 "2015-08-29T06:19:08Z")

</div>

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.

or

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.

---

<div class="post-metadata">

**Author:** ![rdtorres](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rdtorres/32/2851_2.png) [@rdtorres](https://discuss.gradle.org/u/rdtorres)\
**Post date:** [August 29, 2015, 8:04am UTC](https://discuss.gradle.org/t/idea-plugin-iml-withxml-not-executed-if-project-is-imported-from-gradle/11390/3 "2015-08-29T08:04:54Z")

</div>

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.

[]'s  
Rafael Torres

---

<div class="post-metadata">

**Author:** ![DPUkyle](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/dpukyle/32/3671_2.png) [@DPUkyle](https://discuss.gradle.org/u/DPUkyle)\
**Post date:** [October 21, 2017, 6:57pm UTC](https://discuss.gradle.org/t/idea-plugin-iml-withxml-not-executed-if-project-is-imported-from-gradle/11390/4 "2017-10-21T18:57:14Z")

</div>

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 {
  scopes.TEST.plus += [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.
