Brief examples on how to use the enforcer goals.
See the following links for information about including and configuring plugins in your project:
These goals are meant to be bound to a lifecycle phase and configured in your pom.xml. The enforcers execute the configured rules to check for certain constraints. The available standard rules are described here. Besides the rules to execute, these goals support three options:
Each rule to be executed should be added to the rules element along with the specific configuration for that rule.
As of version 2.0 you may add a level element to the standard rules. Valid values are WARN and ERROR. When level WARN is specified, the rule will only spit out a warning but will not fail the build.
The enforce goal executes against each project in a multi-project build. The enforce-once goal executes just once per build. This is most effective for the standard rules because the Maven, Java and OS versions will not change between projects in the same build.
Sample Plugin Configuration:
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.4</version> <executions> <execution> <id>enforce-versions</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <bannedPlugins> <!-- will only display a warning but does not fail the build. --> <level>WARN</level> <excludes> <exclude>org.apache.maven.plugins:maven-verifier-plugin</exclude> </excludes> <message>Please consider using the maven-invoker-plugin (http://maven.apache.org/plugins/maven-invoker-plugin/)!</message> </bannedPlugins> <requireMavenVersion> <version>2.0.6</version> </requireMavenVersion> <requireJavaVersion> <version>1.5</version> </requireJavaVersion> <requireOS> <family>unix</family> </requireOS> </rules> </configuration> </execution> </executions> </plugin> </plugins> </build> [...] </project>
This goal is used to determine the current information as detected by the standard rules:
mvn enforcer:display-info ... [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