title: IntelliJ: Invalid .iml location and content when I choose "create new project" over "open existing project"
body: <p>I have several question about how the project structure is created and stored. Here is the context: I have a git repository containing some groovy files which I use for a Jenkins library. So what is interesting us here is the "src" folder, which contains groovy classes, and the "vars" folder, which contains groovy scripts (DSL).</p>
  
  <p>There's no existing IntelliJ project, no .idea folder, no .iml, no pom.xml ...</p>
  
  <p>Let's say that the repository is located under:</p>
  
  <pre><code>C:\Toto\JenkinsLibrary
     - .git
     - src
     - vars
  </code></pre>
  
  <p>My objective is to create a Maven project from scratch.</p>
  
  <p><strong>First Method:</strong></p>
  
  <p>Initially, I open IntelliJ and choose "Create new project". Select "Maven", no archetype, then I enter the following information:</p>
  
  <ul>
  <li>Project name: I leave the project corresponding to the artifactID: JenkinsBuildLibrary</li>
  <li>Project location: C:\Toto\JenkinsLibrary</li>
  <li>More settings: Module name = JenkinsLibrary, Content root = Module file location = C:\Toto\JenkinsLibrary, Project format = .idea</li>
  </ul>
  
  <p>Then click finish</p>
  
  <p>Here, the .iml file is generated OUTSIDE the .idea folder, looking like this:</p>
  
  <pre><code>C:\Toto\JenkinsLibrary
     - .git
     - .idea
     - src
     - vars
     - JenkinsLibrary.iml
     - pom.xml
  
  
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;module type="JAVA_MODULE" version="4"&gt;
    &lt;component name="NewModuleRootManager" inherit-compiler-output="true"&gt;
      &lt;exclude-output /&gt;
      &lt;content url="file://$MODULE_DIR$" /&gt;
      &lt;orderEntry type="inheritedJdk" /&gt;
      &lt;orderEntry type="sourceFolder" forTests="false" /&gt;
    &lt;/component&gt;
  &lt;/module&gt;
  </code></pre>
  
  <p>Then soon after the content of the iml goes to:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;module type="JAVA_MODULE" version="4" /&gt;
  </code></pre>
  
  <p>Also, I have been trying to reproduce this several times and it is extremely complex to get a consistent behavior, sometimes I have the iml file with no generated pom, sometimes I have the pom with no iml .... so I guess there's a huge bug here.</p>
  
  <p>Finally, if I change the project structure by adding other sources folder or other modules, nothing changes in my .iml file. Then I can close IntelliJ, remove ALL .idea, .iml and pom.xml files ... to get everything back once I reopen IntelliJ, leaving me to wonder: where is that configuration actually stored ?!</p>
  
  <p><strong>Second method:</strong></p>
  
  <p>This time, I choose "Open existing project". I select the folder: C:\Toto\JenkinsLibrary
  There's no existing project but it still works and create a new project.</p>
  
  <p>The .iml file is now under the .idea project !!</p>
  
  <pre><code>C:\Toto\JenkinsLibrary
     - .git
     - .idea
       - JenkinsLibrary.iml
     - src
     - vars
     - pom.xml
  </code></pre>
  
  <p>Right click the module, select "Add Framework Support", Maven, and I get a pom file. </p>
  
  <p>When I change the project structure, the .iml is correctly updated. Exemple:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;module type="JAVA_MODULE" version="4"&gt;
    &lt;component name="NewModuleRootManager" inherit-compiler-output="true"&gt;
      &lt;exclude-output /&gt;
      &lt;content url="file://$MODULE_DIR$" /&gt;
      &lt;content url="file://$MODULE_DIR$/../../tools/ToolJenkins/src"&gt;
        &lt;sourceFolder url="file://$MODULE_DIR$/../../tools/ToolJenkins/src" isTestSource="false" /&gt;
      &lt;/content&gt;
      &lt;orderEntry type="inheritedJdk" /&gt;
      &lt;orderEntry type="sourceFolder" forTests="false" /&gt;
    &lt;/component&gt;
  &lt;/module&gt;
  </code></pre>
  
  <p>Now If I close IntelliJ, remove ALL .idea, .iml and pom.xml files ... I don't get anything back once I reopen the project (only the files and folder located under the module), which seems a far better behavior !</p>
  
  <p><strong>SHORT SUMMARY:</strong></p>
  
  <ul>
  <li>When creating a new Maven project, the .iml is located at the root of the project instead of under the .idea folder and is invalid. The project structure seems to be stored elsewhere. I have no way to ship a valid project to my teammates.</li>
  <li>When opening a new project, the .iml is located under the .idea folder and is valid. The project structure is stored under it (with warnings that project are defined by a pom file and changes performed under the Project structure menu could be wiped). I can ship a valid project to my teammates.</li>
  </ul>
  
  <p>I need to understand those differences and how IntelliJ works. I hope for a quick answer since this is not the first time we struggle with project structures and may well move back to another, more stable IDE is necessary.</p>
  
  <p>Thanks !</p>