IntelliJ IDEA supports a fully-functional integration with Maven that helps you automate your building process. You can easily create a new Maven project, open and sync an existing one, add a Maven support to any existing IntelliJ IDEA project, configure and manage a multi-module project.
Create a new Maven project
If no project is currently open in IntelliJ IDEA, click Create New Project on the Welcome screen. Otherwise, select from the main menu.
Select Maven from the options on the left.
- Specify project's SDK (JDK) or use the default one and an archetype if you want to use a predefined project template (configure your own archetype by clicking Add Archetype).
- On the next page of the wizard, specify the following Maven coordinates that are added to the pom.xml file:
GroupId - a package of a new project.
ArtifactId - a name of your project.
Version - a version of a new project. By default, this field is specified automatically.
For more information on Maven coordinates, see Maven naming conventions.Click Next.
- If you are creating a project using a Maven archetype, IntelliJ IDEA displays the Maven settings that you can use to set the Maven home directory and Maven repositories. Also, you can check the archetype properties.
- Specify the name and location settings.
Open an existing Maven project
- From the main menu, select File | Open.
Alternatively, click Open or Import on the welcome screen.
- In the dialog that opens, select the pom.xml file of the project you want to open.
In the dialog that opens, click Open as Project.
IntelliJ IDEA opens and syncs the Maven project in the IDE. If you need to adjust importing options when you open the project, refer to the Maven settings.
Add a new Maven module to an existing project
You can add a Maven module to the project in which you are already working.
In the Project tool window, right-click the project folder and select . Alternatively, from the main menu, select to open the New Module wizard.
- If you used main menu to add a module then the process of adding a module is the same as Creating a new Maven project.
If you are adding sub modules by right-clicking the root folder then the process of adding a new module is shorter. You need to specify the name of your module in the Name field. The rest of the information is added automatically and you can use either the default settings or change them according to your preferences.
Configure a multi-module Maven project
You can create a multi-module Maven project in IntelliJ IDEA. The multi-module project is defined by a parent POM file with several sub modules.
Create a Maven parent project. IntelliJ IDEA creates a standard Maven layout including an src folder.
In the Project tool window, remove the src folder since you would only need it in the very rare cases. For your general project, you don't need the src folder for the parent POM.
In the Project tool window, right-click your project (or from the main menu, click File) and select New | Module to add a sub project.
- In the New Module wizard following the instructions on how to add a module, specify the necessary information and click Finish.
The src folder is created automatically and you can open POM and add a packaging that you need. IntelliJ IDEA adds the module to the parent project. IntelliJ IDEA also adds name and the description of the sub project to the parent POM.
Last, but not least, IntelliJ IDEA adds the description of the parent POM to the sub project's POM.You can click in the left gutter to quickly open the parent POM from your sub project.
- You can also add dependencies to the parent POM that will be inherited by the sub projects.
Open Maven tool window to see that all changes made in the parent POM are reflected in sub projects.
Access the Maven settings
Use the Maven settings to configure options such as Maven version, local repository, offline mode, and so on.
- In the Settings/Preferences dialog Ctrl+Alt+S , go to .
On the Maven settings page, configure the available options and click OK to save the changes.
Install the Maven custom version
Download the needed Maven version on your computer.
From the main menu select.
On the Maven settings page, in the Maven home directory field, specify the location of the Maven custom version installation.
Change the JDK version in a Maven project
There are several places where you can change the JDK version that will affect not only your current project, but the whole application as well.
Change the JDK version in the Project Structure
Changing the JDK version in the Project Structure dialog will only affect the current project.
From the main menu, selectCtrl+Alt+Shift+S.
In the dialog that opens, in Project SDK, specify the JDK version and click OK to save the changes.
Change the JDK version for the Maven runner
When IntelliJ IDEA runs Maven goals, it will use the JDK version specified for the Maven runner. By default, IntelliJ IDEA uses the project's JDK.
Changing the JDK for the Maven runner will only affect the current project.
In the Settings/Preferences dialog Ctrl+Alt+S, go to .
On the page that opens, in the JRE field, select the JDK version.
Change the JDK version for the Maven importer
Changing the JDK version for the Maven importer will affect the whole application since it is a part of the Maven global settings. If you want to use the same JDK version as you use in your project for syncing or resolving dependencies, change the JDK version for the importer.https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope