Introduction
Maven is a project management tool. It helps in building, documenting, and managing a project. It is used to manage Java projects.
It is based on Project Object Model (POM). A Project Object Model is an XML file containing information about the project. The POM holds information about various configurations, details about the plugins, and the goals of a project.
In Maven, a Plugin is a reusable code that can be used to compile code, test code, create jar/war files and create documentation of the code. A failsafe plugin is used for integration testing. In Integration testing, we test the interactions between the various components.

In this article, we will discuss what is a failsafe plugin in Maven and how to use it.
Failsafe Plugin
Before diving into the failsafe plugin, let’s discuss some things about maven that will help you understand the failsafe plugin better. We will discuss the Build lifecycle in Maven, followed by what a plugin is.
What is Maven Build Cycle?
Before discussing the failsafe plugin, let’s discuss the Build Lifecycle in Maven.
▶️ There are three build lifecycles in Maven - default, clean, and site.
▶️ These lifecycles have phases. Each phase is responsible for a task. A Phase is made up of a sequence of goals.
▶️ A Goal is a specific task (finer than the phase). A Goal can be attached to zero or more phases.
▶️ A group of goals (the goals might be related to different phases) is called a Plugin.
What is a Plugin?
As we have mentioned earlier in this article, a Plugin is a reusable piece of code that can be used to reuse common build logic across different platforms.
Example - The clean plugin will allow you to clear the target directory, thus cleaning up the earlier build artifacts. You can run the command mvn clean to execute the Clean Plugin.
We hope you have understood a Phase, a Goal, and a Plugin in Maven. Let’s discuss the failsafe plugin now!
What is the failsafe plugin?
A failsafe plugin is used for integration testing. Integration testing is the process of checking the interactions between the different components of the project.
There are Four phases of the failsafe plugin -
Phase Name |
Description |
pre-integration-test |
This phase is for setting up the environment for integration testing. |
integration-test |
This phase is for running the tests. |
post-integration-test |
This phase is for tearing down the integration test environment. |
verify |
This phase is for checking the results of the tests. |
There are only two Goals in the failsafe plugin -
Goal |
Description |
failsafe:integration-test |
It runs the integration test of the environment. |
failsafe:verify |
It verifies that the integration tests have passed. |
The advantage of the failsafe plugin is that if the integration-test phase fails, the build does NOT fail; it runs the next phase i.e., the post-integration-test. The post-integration-test phase tears down the environment safely. Thus, the failsafe plugin takes care of the cleanup. The failed tests are reported during the verify phase only.
How to use the failsafe plugin in your project?
Add the following configurations to your POM.xml file to use the failsafe plugin.
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
The failsafe plugin can be invoked by running the following command -
mvn verify
NOTE: To run the integration tests, DO NOT invoke the phases integration-test, pre-integration-test and post-integration-test directly, only invoke verify phase. Invoking any phase other than verify will leave a jetty container (a jetty container is a java web server or a java servlet) running.