To start with a Maven project, first thing is we need to create a pom.xml file, this file acts like a master configuration for Maven based projects where we will define what are other dependencies, plugins such as what artifacts to build and several other settings. Below is a sample POM xml file.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>io.cscode.tools</groupId> <artifactId>my-app</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <properties> <maven.compiler.source>14</maven.compiler.source> <maven.compiler.target>14</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency> </dependencies> </project>

All the settings related to Maven project are specified under project tag and there are some mandatory tags that we need to define such as groupId, artifactId and version etc.

parent - child

If you are working multiple Maven projects and/or modules where there are common dependencies across all projects, to avoid redundancies and duplicate configurations across these projects, you can create a parent project where common dependencies are defined and use that in child projects.

If there is any dependency or properties are configured in both parent POM as well as child POM, then child POM value takes the priority.

Easiest way of creating Maven project in modern IDEs are to just create a pom.xml and mark the project as Maven project, many modern IDEs have this option.

Intellij IDEA

Intellij IDEA default installation comes up with an inbuilt Maven plugin. To create a Maven project, go to File New Project and choose Maven from Left side navigation menu and hit Next

Note: You can choose 'Create from archetype' if you wish to. (Archetype is a Maven project templating toolkit, meaning that template automatically adds necessary dependencies, plugins etc. in the pom.xml file.)

Intellij IDEA create a new Maven project

Enter a Name for the project and choose a directory Location for project files and hit Finish and your Maven project is ready.

Intellij IDEA create a new Maven project, add project name and location

If you want to change Maven related settings, such as Maven home (or) User settings file (or) Local repository location, go to File Settings, then on the left side menu options navigate through Build, Execution, Deployment Build Tools Maven

Intellij IDEA Maven settings
Eclipse IDE

Eclipse default installation comes up with an inbuilt Maven plugin.

To create a Maven project, go to File New Other and select Maven Project option under Maven and hit Next

Eclipse IDE create a new Maven project

In the next screen check Create a simple project option and choose a Location directory for the project.

Note: If you can want to create your project from an archetype, you can uncheck 'Create a simple project' option. (Archetype is a Maven project templating toolkit, meaning that template automatically adds necessary dependencies, plugins etc. in the pom.xml file.)

Eclipse IDE create a new Maven project, add location

In the next screen, enter values for Group Id, Artifact Id and Version and hit Finish and your Maven project is ready.

Eclipse IDE create a new Maven project, add group id, artifact id and version

If you want to change Maven settings such Maven home (or) User settings file (or) Local repository, follow below steps

To change Maven home, go to Window Preferences, then on the left side navigation options, navigate through Maven Installations

Eclipse IDE change Maven home

Now, Click on Add to add new Maven home that you wish to change to, enter Installation home and Installation name (installation name could be any meaningful name, something like Maven3.1) and hit Finish

Eclipse IDE change Maven home

To change Maven settings file, navigate through Maven User Settings and select the settings file you wish to use.

Eclipse IDE change Maven settings