Invaild .iml location and content when I choose "create new project" over "open existing project"

Answered

Hi,

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).

There's no existing IntelliJ project, no .idea folder, no .iml, no pom.xml ...

Let's say that the repository is located under:

C:\Toto\JenkinsLibrary
- .git
- src
- vars


My objective is to create a Maven project from scratch.

First Method:

Initially, I open IntelliJ and choose "Create new project". Select "Maven", no archetype, then I enter the following information:

- Project name: I leave the project corresponding to the artifactID: JenkinsBuildLibrary
- Project location: C:\Toto\JenkinsLibrary
- More settings: Module name = JenkinsLibrary, Content root = Module file location = C:\Toto\JenkinsLibrary, Project format = .idea

Then click finish

Here, the .iml file is generated OUTSIDE the .idea folder, looking like this:

C:\Toto\JenkinsLibrary
- .git
- .idea
- src
- vars
- JenkinsLibrary.iml
- pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

Then soon after the content of the iml goes to:

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />

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.

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 ?!

Second method:

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.

The .iml file is now under the .idea project !!

C:\Toto\JenkinsLibrary
- .git
- .idea
- JenkinsLibrary.iml
- src
- vars
- pom.xml

Right click the module, select "Add Framework Support", Maven, and I get a pom file.

When I change the project structure, the .iml is correctly updated. Exemple:

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$/../../tools/ToolJenkins/src">
<sourceFolder url="file://$MODULE_DIR$/../../tools/ToolJenkins/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

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 !


SHORT SUMMARY:

- 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.
- 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.

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.

Thanks !

4 comments
Comment actions Permalink

See also notes for the Maven support at the bottom for more details:

By default, a newly created or imported project is stored externally. That means that generated iml and library files are stored in idea.system.path instead of the .idea directory. It might be helpful for sharing your project via version control.

If you need to change this behavior, open the Maven settings (Settings | Maven | Importing) and clear the Store generated project files externally checkbox.

0
Comment actions Permalink

Thank you, that is still unclear to be honest (I added comments on my stack overflow post). My main point of discomfort is that I struggle to get a consistent behavior and this prevent me to understand what my actions actually do.

I have added the build structure to my pom file (since I cannot follow the standard convention), the .idea/.iml file changed after that, and an ./<artefactId>.iml file was created after that.
In IntelliJ I still see the other folders which is great because I need them even if they do not build (Jenkins DSL are not build-able and therefore cannot be tested by Maven, src contains classes so it can).

My question now is that I must reference a new project as a dependency of the current one. This project as a pom.xml file, how should I proceed to add this project to my pom file ?

0
Comment actions Permalink

In case of Maven project you should configure project structure and dependencies in pom.xml files and should not be bothered with the project configuration files. Why do you need them? The whole point is to provide in IDE the same behaviour as you would get when build project by Maven from command line.

>My question now is that I must reference a new project as a dependency of the current one. This project as a pom.xml file, how should I proceed to add this project to my pom file ?

See Guide to Working with Multiple Modules and this SO post as an example: https://stackoverflow.com/q/4150180/2000323

0

Please sign in to leave a comment.