Creating IntelliJ Projects from Maven: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(24 intermediate revisions by the same user not shown)
Line 26: Line 26:
==Import Project Main Window==
==Import Project Main Window==


'''Root directory''' The project's root directory, the place where the root pom.xml file lives.
'''Root directory''' The project's root directory, the place where the top level pom.xml file lives.


'''Search for projects recursively''' From IntelliJ documentation: "Select this check box to make import look for the nested pom.xml files".
'''Search for projects recursively''' From IntelliJ documentation: "Select this check box to make import look for the nested pom.xml files". I noticed that even if I don't check it, Maven modules (which have corresponding pom.xml files in sub-directories) are still detected.


I noticed that even if I don't check it, Maven modules (which have corresponding pom.xml files in sub-directories) are still detected.
What to do: DO NOT CHECK.


'''Project format''' ".idea (directory based)" should be the default.
'''Project format''' ".idea (directory based)" should be the default.
Line 38: Line 38:
From documentation: ''Select this check box to specify the desired location for storing project and module files.'' This means the .idea directory and the module files (.iml). If not selected (and no directory specified), the <tt>.idea</tt> directory is kept in the project's root directory, and the .iml files are kept beside the corresponding pom.xml files. Note that the IntelliJ module descriptor files (.iml) will NOT be maintained under <tt>.idea</tt>. Also see [[#Project_name_and_Project_file_location_Window|Project name and Project file location Window]].
From documentation: ''Select this check box to specify the desired location for storing project and module files.'' This means the .idea directory and the module files (.iml). If not selected (and no directory specified), the <tt>.idea</tt> directory is kept in the project's root directory, and the .iml files are kept beside the corresponding pom.xml files. Note that the IntelliJ module descriptor files (.iml) will NOT be maintained under <tt>.idea</tt>. Also see [[#Project_name_and_Project_file_location_Window|Project name and Project file location Window]].


DO NOT check, do not change the defaults, otherwise all .iml files will be created in that directory, and this is probably not what you want.
What to do: DO NOT check, do not change the defaults, otherwise all .iml files will be created in that directory, and this is probably not what you want.


'''Import Maven projects automatically''' If checked, IntelliJ will re-import the project automatically every time the pom.xml file(s)(?) is/are changed.  
'''Import Maven projects automatically''' If checked, IntelliJ will re-import the project automatically every time the pom.xml file(s)(?) is/are changed.  


'''Create IntelliJ IDEA modules for aggregator projects (with 'pom' packaging)'''. Clear this check box to skip creating IntelliJ IDEA modules. You might want to do that if the Maven project you import is an aggregator, and its packaging element has the value pom. By default is enabled. <font color=red>What if I want the behavior for some of them, and I don't for others?</font>
What to do: DO CHECK.


If not checked, IntelliJ won't create an .iml for the root pom.xml, and the Project view looks like this, even if there's a "root" pom.xml that aggregates "ear", "lib" and "war":
'''Create IntelliJ IDEA modules for aggregator projects (with 'pom' packaging)'''. Clear this check box to skip creating IntelliJ IDEA modules. You might want to do that if the Maven project you import is an aggregator, and its packaging element has the value pom. By default is enabled. If not checked, IntelliJ won't create an .iml for the root pom.xml, and the Project view looks like this, even if there's a "root" pom.xml that aggregates "ear", "lib" and "war":


[[Image:ProjectView.png|center]]
[[Image:ProjectView.png|center]]


It's probably a good idea to NOT check it, keeps things simpler. <font color=red>What if the top pom contains dependencies for modules - if the corresponding .iml is not created, then those dependencies are probably not known to IntelliJ. Further experimentation needed.</font>
<font color=red>What if the top pom contains dependencies for modules - if the corresponding .iml is not created, then those dependencies are probably not known to IntelliJ. Further experimentation needed.
</font>


'''Create module groups for multi-module Maven projects''' If checked, a module group will be created from an aggregator Maven project, with nested modules included in the group.
What to do: DO CHECK.


<font color=red>Further experimentation needed.</font>
'''Create module groups for multi-module Maven projects''' If checked, a module group will be created from an aggregator Maven project, with nested modules included in the group. Note that if we don't create IntelliJ modules for aggregator Maven modules, checking this has no effect.


__Keep source and test folders on reimport__ - <font color=red>If this check box is selected, the source and test folders are kept when you reimport a project. What does this mean?</font>
What to do: DO CHECK.


'''Keep source and test folders on reimport''' <font color=red>If this check box is selected, the source and test folders are kept when you reimport a project. What does this mean?</font>


__Exclude build directory (PROJECT_ROOT/target)__ Enables automatic exclusion of target folders. However if /target contains /target/generated-sources, then /target cannot be excluded since /target/generated-sources is marked as sources. Other subdirectories in /target are excluded.
'''Exclude build directory (PROJECT_ROOT/target)''' Enables automatic exclusion of target folders. However if /target contains /target/generated-sources, then /target cannot be excluded since /target/generated-sources is marked as sources. Other subdirectories in /target are excluded.


__Use Maven output directories__ If selected, the build is generated in target, and the results of IntelliJ compilation are reused. However, IntelliJ itself does not reuse the Maven build, and performs the compilation from scratch.
'''Use Maven output directories''' If selected, the build is generated in target, and the results of IntelliJ compilation are reused. However, IntelliJ itself does not reuse the Maven build, and performs the compilation from scratch.


'''Generate source folders''' ''Specify the directory of your source root when you reimport a project. You can select one of the following options: 1) Detect automatically This is a default option. When you select this option, IntelliJ IDEA automatically detects the location of the generated sources. IntelliJ IDEA also detects which directory to mark as a source root. Note that IntelliJ IDEA searches for the generated sources only in target/generated-sources and target/generated-sources/* directories.
2) target/generated-sources This option enables you to mark the directory as a source root manually. 3) subdirectories of "target/generated-sources" This option enables you to mark a subdirectory as a source root manually.''


__Generate source folders__
'''Phase to be used for folder update''' "process-resources"
 
'''Automatically download''' ''Specify the automatic download of sources and documentation comments into a local repository when you open a Maven project. ''
 
What to do: Check Sources.


==Project name and Project file location Window==
==Project name and Project file location Window==


'''Project name''' The name of the IntelliJ project, the way the project will show up
'''Project name''' The name of the IntelliJ project. Will be shown on the title bar of the main project window, as shown below ("Playground JEE EAR with lib and WAR):
 
[[Image:ProjectName.png|center]]


Internally, it is stored in the <tt>.idea/.name</tt> file.
If you want to change it, for a reason I can't explain, IntelliJ attempts to use the name in the "Project file location" below. Resist that, change it back to what it was.


The default value is the artifactId of the top level pom. After set up, internally it is stored in the <tt>.idea/.name</tt> file.


'''Project file location''' From documentation ''Specify the location of your project directory where IntelliJ IDEA stores the configuration data for your project and its components.''
'''Project file location''' From documentation ''Specify the location of your project directory where IntelliJ IDEA stores the configuration data for your project and its components.''
<font color=red>How does this relate to "Keep project files in:" above?</font>
Also see:
<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;">
:[[How to Change IntelliJ Project Name after project Creation]]
</blockquote>


=Other Observations=
=Other Observations=


==.iml Module File Names==
==pom.xml <artifactId>s and .iml Module File Names==


IntelliJ names the module file .iml using the <tt><artifactId></tt> value of their corresponding pom.xml file.
IntelliJ names the module file .iml using the <tt><artifactId></tt> value of their corresponding pom.xml file. The pom.xml <tt><name></tt> seems to be ignored.

Latest revision as of 21:16, 18 March 2016

External

Internal

Relevance

IntelliJ 14

Overview

This article describes the process of creating an IntelliJ project based on an existing Maven multi-module structure.

Procedure

Import Project -> Select File or Directory to Import

Choose the directory that contains the root pom.xml.

Import project from external model -> Maven

Import Project Main Window

Root directory The project's root directory, the place where the top level pom.xml file lives.

Search for projects recursively From IntelliJ documentation: "Select this check box to make import look for the nested pom.xml files". I noticed that even if I don't check it, Maven modules (which have corresponding pom.xml files in sub-directories) are still detected.

What to do: DO NOT CHECK.

Project format ".idea (directory based)" should be the default.

Keep project files in:

From documentation: Select this check box to specify the desired location for storing project and module files. This means the .idea directory and the module files (.iml). If not selected (and no directory specified), the .idea directory is kept in the project's root directory, and the .iml files are kept beside the corresponding pom.xml files. Note that the IntelliJ module descriptor files (.iml) will NOT be maintained under .idea. Also see Project name and Project file location Window.

What to do: DO NOT check, do not change the defaults, otherwise all .iml files will be created in that directory, and this is probably not what you want.

Import Maven projects automatically If checked, IntelliJ will re-import the project automatically every time the pom.xml file(s)(?) is/are changed.

What to do: DO CHECK.

Create IntelliJ IDEA modules for aggregator projects (with 'pom' packaging). Clear this check box to skip creating IntelliJ IDEA modules. You might want to do that if the Maven project you import is an aggregator, and its packaging element has the value pom. By default is enabled. If not checked, IntelliJ won't create an .iml for the root pom.xml, and the Project view looks like this, even if there's a "root" pom.xml that aggregates "ear", "lib" and "war":

ProjectView.png

What if the top pom contains dependencies for modules - if the corresponding .iml is not created, then those dependencies are probably not known to IntelliJ. Further experimentation needed.

What to do: DO CHECK.

Create module groups for multi-module Maven projects If checked, a module group will be created from an aggregator Maven project, with nested modules included in the group. Note that if we don't create IntelliJ modules for aggregator Maven modules, checking this has no effect.

What to do: DO CHECK.

Keep source and test folders on reimport If this check box is selected, the source and test folders are kept when you reimport a project. What does this mean?

Exclude build directory (PROJECT_ROOT/target) Enables automatic exclusion of target folders. However if /target contains /target/generated-sources, then /target cannot be excluded since /target/generated-sources is marked as sources. Other subdirectories in /target are excluded.

Use Maven output directories If selected, the build is generated in target, and the results of IntelliJ compilation are reused. However, IntelliJ itself does not reuse the Maven build, and performs the compilation from scratch.

Generate source folders Specify the directory of your source root when you reimport a project. You can select one of the following options: 1) Detect automatically This is a default option. When you select this option, IntelliJ IDEA automatically detects the location of the generated sources. IntelliJ IDEA also detects which directory to mark as a source root. Note that IntelliJ IDEA searches for the generated sources only in target/generated-sources and target/generated-sources/* directories. 2) target/generated-sources This option enables you to mark the directory as a source root manually. 3) subdirectories of "target/generated-sources" This option enables you to mark a subdirectory as a source root manually.

Phase to be used for folder update "process-resources"

Automatically download Specify the automatic download of sources and documentation comments into a local repository when you open a Maven project.

What to do: Check Sources.

Project name and Project file location Window

Project name The name of the IntelliJ project. Will be shown on the title bar of the main project window, as shown below ("Playground JEE EAR with lib and WAR):

ProjectName.png

If you want to change it, for a reason I can't explain, IntelliJ attempts to use the name in the "Project file location" below. Resist that, change it back to what it was.

The default value is the artifactId of the top level pom. After set up, internally it is stored in the .idea/.name file.

Project file location From documentation Specify the location of your project directory where IntelliJ IDEA stores the configuration data for your project and its components.

How does this relate to "Keep project files in:" above?

Also see:

How to Change IntelliJ Project Name after project Creation

Other Observations

pom.xml <artifactId>s and .iml Module File Names

IntelliJ names the module file .iml using the <artifactId> value of their corresponding pom.xml file. The pom.xml <name> seems to be ignored.