Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Table of contents
Enforcer Plugin
Example Plugin Configurations
Frequently Asked Questions
How can we fix require upper bound dependencies error in Maven? 
What is the difference between phase and goal in Maven?
What is a Plugin in Maven? 
Last Updated: Mar 27, 2024

Maven Enforcer Plugin

Author Neha Chauhan
1 upvote
Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM


Java projects can be managed using Maven i.e. Maven is a project management tool. By using Maven you can build, manage and configure Java projects easily. 

Maven has a centralized repository that stores the dependencies of various software, so you can download the dependencies by visiting mvnreposiroty. It helps in getting the correct libraries and JAR files for your project. Maven will help you create the right project structure for the proper execution of files. 

It is based on the concept of a Project Object Model (POM), which is an XML file holding all the information about the configuration details, plugin details and goals of a project. 

There are many Plugins in Maven, one of them is the Enforcer Plugin which is used to apply and enforce rules on your Maven projects.

Maven Enforcer Plugin

In this article, we will discuss what is an Enforcer Plugin and how to use it in Maven.

Enforcer Plugin

In Maven, a Plugin is a reusable piece of code using which you can apply the same build logic on different platforms without writing the code again and again. 

According to the Cambridge Dictionary, Enforcer means “someone who makes people obey a law or rule, or makes a particular situation happen or be accepted”, so intuitively we can say that the Enforcer plugin will also check that the project holds the required configurations. 

Enforcer Plugin helps in controlling the environment configurations. You can mention the required Maven versions, JDK versions, and OS Family rules. You can also create your own rules. 

Before moving on, let’s understand some basic concepts of Maven - 

▶️ In maven, there are three build phases defaultclean, and site

▶️ Each lifecycle has phases that are responsible for performing many tasks. 

▶️ Each Phase is made up of a sequence of Goals. 

▶️ A Goal in Maven is specific task that will be performed. 

▶️ A group of Goals is called a Plugin

There are two Goals in the Enforcer Plugin

Goal Name



It will execute the rules that you have mentioned. 


It will display the rules that you have applied to your project. It will display the current information that is detected by the built-in rules. 

Let’s understand each goal in detail!


This ‘goal’ of the Enforcer plugin, will go over all the rules and check for certain constraints i.e. it will execute rules specified in the configuration. 

Some built-in Rules of the enforcer:enforce goal are as follows - 




This rule ensures that there are no duplicate dependencies. This rule comes in handy when there exists a parent-child relationship in the POM XML file. 


By applying this rule, you can ensure the java version.


By applying this rule, you can ensure the Maven version.


This rule ensures that the mentioned prerequisites have been mentioned in the project. 


This rule ensures that the required environment variables have been set.


This rule ensures that the specified dependencies and plugins have same versions. 


This rule will always fail and is used to test proper plugin configurations.


This rule will always pass and is used to test proper plugin configurations.


It ensures that the mentioned files are present and the size of the file is as required. 

This goal supports three Options

skip: use this option if you want to skip any kind of rule. You can do this by using -Denforcer.skip 

fail: use this option, if you want the build to fail if a rule fails. By default, the build will fail if the rule fails but if you want to just show the failed build as warning then set the fail to False. 

failFast: if the goal should stop checking after the first failure. The default is false.

Example Plugin Configurations

                  <!-- will only display a warning but does not fail the build. -->
                  <message>Please consider using the maven-invoker-plugin (!</message>


As the name suggests, this rule is used to determine the current configurations of the project. 

  mvn enforcer:display-info
       Maven Version: 2.0.6
       JDK Version: 1.5.0_11 normalized as: 1.5.0-11
       OS Info: Arch: x86 Family: windows Name: windows xp Version: 5.1
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job

Frequently Asked Questions

How can we fix require upper bound dependencies error in Maven? 

Update the version in the pom. xml to the newest version listed in the output from maven-enforcer-plugin, in case that artifact is already declared in the pom.xml. You can apply the requireUpperBoundDeps to ensure that the dependencies are in correct inheritance. 

What is the difference between phase and goal in Maven?

A Phase is a collection of goals that perform a task. When we run a phase, several different goals that are included in the phase run in a pre-defined sequence. A Goal is specific task that needs to be performed, it is much finer task than a Phase. For example, in compiler:compile - compile is the Goal for the compiler phase of the compiler plugin. 

What is a Plugin in Maven? 

A Plugin is the heart of Maven. It is a reusable piece of code that can be used to reuse the common build logic across different platforms. A Plugin is a group of different goals. These goals might or might not be related to each other. 


In this article, we have discussed what is the Enforcer Plugin in Maven. We discussed about the two goals provided by the Enforcer Plugin - enforcer:enforce and enforcer:display-info in details along with some rules and options supported by the enforcer:enforce goal of the enforcer plugin. 

Do not stop learning! We recommend you read these articles- 

🔥 Maven Eclipse Plugin

🔥 Maven Plugins

Head to the Guided Path on the Coding Ninjas Studio and upskill in Data Structures and AlgorithmsCompetitive ProgrammingSystem Design, and many more courses.

If you want to Practice top Coding Problems, attempt mock tests, or read interview experiences, head to the Coding Ninjas Studio, our practice platform.

We wish you Good Luck!🎈 Please upvote our blog 🏆 and help other ninjas grow.

Live masterclass