Agentic AI with Java: Live Cohort
MavenDependencies, POM & IDEs

Maven in IntelliJ IDE

Create a Maven project in IntelliJ IDEA, find the same standard structure you built from the terminal, and run clean, compile, test and package from the Maven tool window.

Everything we did in the terminal also works from an IDE, and in day to day development that is how most people use Maven. The important thing to understand is that the IDE does not replace Maven. It runs the same Maven, reads the same pom.xml, and produces the same target folder. The project structure is identical whichever IDE you use.

Create the project

Open the New Project dialog

In IntelliJ IDEA choose File > New > Project (or New Project on the welcome screen).

Fill in the basics

FieldValue in the demoNotes
NameMavenDemoAppBecomes the folder name and the default artifactId
LocationD:\Maven ProjectsAny folder you like
Build systemMavenThe choice that matters. IntelliJ and Gradle are the other options
JDK21Any JDK 17 or newer
Add sample codetickedCreates a Main class

Expand Advanced Settings to set the GroupId (for example com.telusko) and ArtifactId. If you leave GroupId alone, IntelliJ uses org.example, which is why the video's project ends up with an org.example package.

IntelliJ IDEA New Project dialog with name MavenDemoApp, location D:\Maven Projects, build system Maven selected and JDK 21

The New Project dialog with Maven selected as the build system.

Create

Click Create and choose to open it in the current window or a new one. IntelliJ generates the project and imports it as a Maven project.

The same structure as before

The project tool window on the left shows a familiar layout:

MavenDemoApp/
├── pom.xml
└── src/
    ├── main/
    │   ├── java/org/example/Main.java
    │   └── resources/
    └── test/
        └── java/

Open pom.xml. IntelliJ already set the Java version through properties, the same technique you learned in Maven POM.xml file:

<properties>
  <maven.compiler.source>21</maven.compiler.source>
  <maven.compiler.target>21</maven.compiler.target>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

The Maven tool window

Click the m icon on the right edge (or View > Tool Windows > Maven). It has three useful nodes:

NodeWhat it shows
LifecycleThe common phases: clean, validate, compile, test, package, verify, install, site, deploy
PluginsEvery plugin the project uses (clean, compiler, surefire, jar, install, deploy and so on) with its version, and each plugin's individual goals such as compiler:compile
RepositoriesThe local repository (~/.m2/repository) and central (https://repo.maven.apache.org/maven2) you learned about in Maven Repositories
IntelliJ IDEA Maven tool window showing the Lifecycle phases, the Plugins list with versions, and the local and central Repositories

The Maven tool window: lifecycle phases at the top, plugins with their versions, then the local and central repositories.

Notice that the Plugins node lists plugins you never added to pom.xml. They come from Maven's built-in defaults, which is exactly what the next lesson, Effective POM, explains.

Run goals from the IDE

Double click a phase under Lifecycle to run it (or right click it and choose Run). The Run panel at the bottom shows the same output you saw in the terminal.

Double clickSame asResult
cleanmvn cleantarget/ deleted
compilemvn compiletarget/classes created
testmvn testTests compiled and run
packagemvn packagetarget/MavenDemoApp-1.0-SNAPSHOT.jar created. The Run panel prints the full path

You can select several phases with Ctrl+click and run them together, for example clean and package. install and deploy work too, and we cover what they do in the lifecycle lesson. deploy needs extra configuration (where to deploy), so it will fail on this demo project, which is expected.

You can still open the Terminal tab inside IntelliJ and type mvn clean package yourself. Both ways give the same result.

Two IntelliJ habits worth learning

Try It Yourself

  1. Create MavenDemoApp in IntelliJ with GroupId com.telusko and run package from the Maven tool window.
  2. In the Plugins node, find the version of maven-surefire-plugin your project uses.
  3. Add the spring-core dependency to the POM, reload the project, and confirm it appears under External Libraries.
  4. Run mvn clean package from IntelliJ's Terminal tab and compare the output with the tool window run.

Official references


Written By: Shramik Masti

How is this guide?

Last updated on