eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

eBook – Maven – NPI (cat=Maven)
announcement - icon

Get up to speed with the core of Maven quickly, and then go beyond the foundations into the more powerful functionality of the build tool, such as profiles, scopes, multi-module projects and quite a bit more:

>> Download the core Maven eBook

1. Introduction

Apache Maven is a powerful build management tool that provides a structured way to manage the build lifecycle of a project. Maven builds are composed of lifecycles, which define clearly how a project is built and distributed.

Two very useful commands that play a key role in the build process are mvn install and mvn verify. In this tutorial, we’ll compare and contrast these two commands, understanding the differences between them.

2. Maven Lifecycles

Maven defines three standard lifecycles — clean, default, and site — where each one has a distinct purpose:

  • The clean lifecycle is responsible for cleaning the project.
  • The default lifecycle is for building and deploying.
  • The site lifecycle is for creating the project’s site documentation.

Each lifecycle consists of phases, and each phase represents a stage in the lifecycle.

2.1. Maven’s default Lifecycle

The default lifecycle handles the build process, starting from project compilation and ending with the deployment of artifacts. It is composed of 23 phases and below are the six major phases:

  1. validate: The project is validated to ensure that all necessary information is available for the build.
  2. compile: The source code is compiled into bytecode.
  3. test: Unit tests are executed to ensure the code’s correctness.
  4. package: The compiled code is packaged into a JAR or WAR file, depending on the project type.
  5. verify: Additional verification checks run, typically integration tests or ones specified by plugins.
  6. install: The packaged artifact is installed into the local Maven repository, ~/.m2/repository, making it available for other projects on the same machine.

When running a command, we only need to call the last build phase we want to be executed. For instance, running mvn test will execute, in order, the validate, compile, and test phases.

3. Setup

In our pom.xml, let’s import a dependency for the maven-surefire-plugin that’s required to run unit tests during the test phase:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.1.2</version>
</plugin>

Let’s also import and configure the dependency configure the maven-failsafe-plugin, binding the integration-test goal to the integration-test phase and the verify goal to the verify phase:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>3.1.2</version>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Next, let’s write a simple Java program that returns a String when executed:

class CourseApp {
    String getCourse() {
        return "Baeldung Spring Masterclass";
    }
}

We’ll define a unit test that will be executed as part of the test phase:

@Test
void whenGetCourse_ThenCourseShouldBePresent() {
    CourseApp courseApp = new CourseApp();
    
    assertEquals("Baeldung Spring Masterclass", courseApp.getCourse());
}

Similarly, a simple integration test will be executed as part of the integration-test goal of the verify phase.

@Test
void givenIntegrationTest_whenGetCourse_ThenCourseShouldBePresent() {
    CourseApp courseApp = new CourseApp();
    
    assertEquals("Baeldung Spring Masterclass", courseApp.getCourse());
} class="language-xml">

4. Maven Verify Phase

The mvn verify command triggers five phases: validate, compile, test, package, and verify. The verify phase is intended to be used for verifying a project’s integrity and quality.

Since we bound the verify phase to the integration-test goal using the maven-failsafe-plugin, our integration tests will run. Maven considers the project verified only if both unit and integration tests pass:

Maven Verify Phase

By executing the verify phase, we can ensure that our project undergoes thorough testing, including integration testing, before being packaged into an artifact and distributed. This phase can help us maintain the reliability and quality of our application.

5. Maven Install Phase

On the other hand, mvn install is responsible for installing the project’s artifacts into the local repository. It triggers the install phase, which comes directly after verify. Thus, it serves the double purpose of verifying our code’s quality and installing our artifact locally.

When we run mvn install, Maven executes the install phase in addition to all the previous steps of the verify phase:

Maven install phase

This is particularly useful when working on multiple projects that have dependencies on one another, as it avoids having to copy JAR files between projects manually.

6. Differences Between mvn install and mvn verify

While both mvn install and mvn verify contribute to the default lifecycle and share common phases, they serve slightly different purposes:

  • mvn verify focuses on performing quality checks beyond simple unit testing, such as integration tests and custom checks configured through plugins. It is recommended when the objective is to ensure the project meets specific quality criteria.
  • mvn install is primarily used for installing the project’s artifacts into the local repository. It’s often used during development to share artifacts between projects on the same machine.

7. Conclusion

Understanding the different Maven lifecycles and phases is essential for effective project management and collaboration in a Maven-powered build environment.

In this article, we discussed how mvn install is the go-to command for local development and dependency management. In contrast, we’ve seen how mvn verify can be used to perform integrity and quality checks against our project.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

eBook Jackson – NPI EA – 3 (cat = Jackson)
2 Comments
Oldest
Newest
Inline Feedbacks
View all comments