waffel’s Weblog

November 18, 2010

disable maven enforcer rule

Einsortiert unter: software — Thomas Wabner @ 6:33 nachmittags
Tags: , , , ,

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.

About these ads

3 Kommentare »

  1. Thanks, that was pretty handy way to disable an inherrited enforcer rule!

    Kommentar von ross — September 27, 2011 @ 12:30 nachmittags | Antwort

  2. OR you can use -Denforcer.skip=true

    Kommentar von Ranga — Januar 12, 2012 @ 1:43 nachmittags | Antwort

    • Thanks Ranga,

      yes and No … if you want to disable ALL enforcer rules you are right … but with my suggested approach you can skip/disable a specific rule (often you have many different enforcer rules and you want for example skip only a subset of them … in my example the java-1.4 enforcing).

      Kommentar von Thomas Wabner — Januar 12, 2012 @ 2:21 nachmittags | Antwort


RSS-Feed für Kommentare zu diesem Beitrag. TrackBack URI

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ photo

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s

The Rubric Theme. Create a free website or blog at WordPress.com.

Follow

Erhalte jeden neuen Beitrag in deinen Posteingang.

Schließe dich 28 Followern an

%d Bloggern gefällt das: