I have a few maven profiles in my pom.xml. I have jenkins configured to run nightly tests for each of these profiles.
I figured today that there was a spelling mistake in one of the profile names in my jenkins config. Turns out that if maven cannot file a profile, it runs the default profile.
Is there a way I can force maven to throw an error if the profile doesn't exist?
A profile in Maven is an alternative set of configuration values which set or override default values. Using a profile, you can customize a build for different environments. Profiles are configured in the pom. xml and are given an identifier.
Maven profiles can be used to create customized build configurations, like targeting a level of test granularity or a specific deployment environment. In this tutorial, we'll learn how to work with Maven profiles.
Maven Enforcer Plugin version 3.0.0-M2 has introduced a built-in check requireProfileIdsExist for this purpose:
When running Maven with one or more unknown profile ids, Maven will give you a warning. This rule will actually break the build for that reason.
Here is how a project should be setup to use this rule
<project> ... <build> <plugins> ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>3.0.0-M2</version> <executions> <execution> <id>enforce</id> <configuration> <rules> <requireProfileIdsExist/> </rules> </configuration> <goals> <goal>enforce</goal> </goals> </execution> </executions> </plugin> ... </plugins> </build> ... </project>
You can use the Maven Enforcer Plugin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With