Igor Khromov blog

Create a simple Maven project with IntelliJ IDEA

1.1. Open IDEA and select “Create New Project”.

1.2. Select the project type.

In the left-side menu select “Maven” and click Next.

1.3. Set GropId, ArtifactId, and Version.

The GroupId is a name that used to uniquely identify your project between all other projects, the good example of GroupId is org.apache.maven.

The ArtifactId is a name of *.jar file without version. In most cases, this is a word (formed with lowercase letters) without special symbols.

The Version in most cases consists of three parts: MAJOR.MINOR.PATCH. For more details and best practises, please visit https://semver.org/.

So in this example, we will use:

  • GroupId: com.igorkhromov
  • ArtifactId: simple-maven-project
  • Version: 1.0.0

Click Next.

1.3. Name the project and set the project location.

In this example, we can set the name like simple-maven-project and home user dir for project location like ~/blog/simple-maven-project.

Click Finish.

1.4. Set Java version in Maven

It’s a good idea to tell to Maven what Java version (1.8 for this example) should be used in a project. For this reason, we can use maven-compiler-plugin with configuration section:

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>com.igorkhromov</groupId>
    <artifactId>simple-maven-project</artifactId>
    <version>1.0.0</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Congratulations, you are done!

1.5. Github repository with example

Github: https://github.com/xrom888/blog_simple-maven-project-idea

To clone the repository in current dir, run in terminal:

git clone git@github.com:xrom888/blog_simple-maven-project-idea.git