19 Nov 2010 waffel   » (Journeyer)

disable maven enforcer rule

Apache maven enforcer rules are very useful in large projects. A common usage of such enforcer rules is to define them in a central point like a project parent pom.xml. For example following enforcer definition can be set in a pom parent:

package-parent pom.xml:

...
<plugin>
  <artifactId>maven-enforcer-plugin</artifactId>
     <executions>
       <execution>
         <id>enforce-java-1_4</id>
         <goals>
           <goal>enforce</goal>
         </goals>
         <configuration>
           <rules>
             <requireProperty>
                <property>java.compiler.version</property>
                <regex>1\.4</regex>
                <regexMessage>You must compile with Java 1.4, as long our servers run in old NetWeaver!</regexMessage>
              </requireProperty>
            </rules>
            <fail>true</fail>
         </configuration>
      </execution>
    </executions>
</plugin>
...

This enforcer rule should ensure that all projects, which using the parent POM using a Java 1.4 compiler.

Often such parent pom defines many other useful properties and settings for projects. If you want to use these definition and ONLY want to disable the enforcer rule you can simple do follow „trick“:

...
<parent>
  <groupId>org.waffel</groupId>
  <artifactId>package-parent</artifactId>
  <version>1.1</version>
</parent>

<build>
   <plugins>
     <!-- we need to overide the enforcer rules here because we have java 1.6 and not the  old 1.4 -->
      <plugin>
        <artifactId>maven-enforcer-plugin</artifactId>
        <executions>
          <execution>
            <id>enforce-java-1_4</id>
            <phase>none</phase>
          </execution>
        </executions>
      </plugin>
   </plugins>
</build>
...

I use the same approach here as described in my article how to diable a inherited maven plugin.


Filed under: software Tagged: disable, enforcer, maven, plugin, rule

Syndicated 2010-11-18 16:33:22 from waffel's Weblog

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!