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.
Thanks, that was pretty handy way to disable an inherrited enforcer rule!
Kommentar von ross — September 27, 2011 @ 12:30 nachmittags |
OR you can use -Denforcer.skip=true
Kommentar von Ranga — Januar 12, 2012 @ 1:43 nachmittags |
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 |