Maven Enforcer Plugin

| | Comments (0) | TrackBacks (0)

If you implement Maven projects that are used and build by several other people it's mostly advisable to validate the reqired environment conditions on the build machine. How nice that Apache provides the Maven-Enforcer-Plugin that allows controlling constraints like the Maven/ JDK versions, the OS version or the existence or value sets of environmental variables.
The Maven-Enforcer-Plugin is called by default during the validate phase of Maven's build lifecycle and lets you define a set of rules that are to be checked.

Here is an example configuration to be placed in your pom.xml:


<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-enforcer-plugin</artifactId>
  <executions>
    <execution>
      <phase>validate</phase>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>

          <!-- Allow any Java >= 1.5, but not 1.6 or above -->
          <requireJavaVersion>
            <version>[1.5,1.6)</version>
          </requireJavaVersion>
               
          <!-- Allow any Maven >= 2.0.5 -->
          <requireMavenVersion>
            <version>[2.0.5,)</version>
          </requireMavenVersion>
 
             
          <!-- Check existence and value of system property -->
          <requireProperty>
            <property>appserver.name</property>
            <message>System property 'appserver.name' is not set!</message>
            <regex>glassfish|jboss</regex>
            <regexMessage>jboss and glassfish are supported!</regexMessage>
          </requireProperty>

        </rules>
      </configuration>
    </execution>
  </executions>
</plugin>

0 TrackBacks

Listed below are links to blogs that reference this entry: Maven Enforcer Plugin.

TrackBack URL for this entry: http://www.innoq.com/mt4/mt-tb.cgi/2437

Leave a comment

About this Entry

This page contains a single entry by Arnd Kleinbeck published on March 2, 2008 6:30 PM.

Maven Profile Trigger is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.0