What are maven profiles? What can you use them for? And, finally, how to do it? Well, since you’re here – let me show you.


Maven profiles are not the most commonly used feature and there is relatively little information on how to use them in practice. They can be used to differentiate builds of the same application; virtually every element specified in one’s pom.xml may be used conditionally based on profiles. What can you use maven profiles for in real life? Mostly they are used to configure builds for different environments (test/production), though it is argued that it shouldn’t be done. In our case, we used maven profiles to prepare builds for specific application servers.

The problem

Our case was simple: we had to prepare builds for two different application servers, a tomcat and a jetty. Spring-boot’s dependencies for those servers were incompatible with one another – deploying a build on tomcat with jetty dependencies failed, and deploying tomcat build on jetty had some logging issues. While that situation was temporary, it was a severe problem we had to solve.

The solution

We’ve used maven profiles. The dependencies sections are what’s going to be different for profiles in our case. We’ve declared two profiles which defined which of the conflicting dependencies were to be used. Our profiles section looked like this:


Secondly, we wanted to make sure that a profile was actually specified during build. We’ve decided that there’d be no default profile and the person making the build would have to make a conscious decision which profile to use. That part required a little bit more work and several attempts to make work. The maven-enforcer-plugin was used to achieve our goal.

Not choosing a profile would cause the build to fail and output the <message> specified above.


We’ve configured maven profiles to build our app differently for different application servers: tomcat and jetty, thus solving the dependencies incompatibility problem. We’ve used maven-enforcer-plugin to make sure that the programmer chose a profile while building the application.